Casts using “as” (Pitfalls and Best Practices to Prevent Them #5)

Well – “as” is faster to type than a “real” cast using two brackets and has the same result. Really?

C# provides several ways to cast one type to another one. The two used in most cases are the “([Targettype]) [Variable]” and the “[Variable] as [Targettype]” notations. Many developers see them as equivalents, some even prefer “as” because it does not throw an exception when the cast fails.


Let’s say we have a variable called obj of type Object and we want to cast it to an IFoo so we can call IFoo.Bar:

object obj;
(obj as IFoo).Bar();

Read the rest of this entry »

Threatfire and Visual Studio –> Debugging slowdown

Something prevented me from debugging!!! Why this excuse can be true in some situations.

Some days ago, I noticed that the Visual Studio 2008 debugger suddenly was very, very slow.

A simple “Step Over” took up to 10 seconds. Even worse was the performance of the “Immediate Window”. When evaluating an expression, the output was terribly slow, too.

As debugging in such a low speed is no fun any more, I had to find the reason. First I thought that changed settings, windows or plugins are responsible.

Read the rest of this entry »