AV1570 Check as for null


An addition to this:

Using the 'as' is more performance when you expect that the object may be of another type. But then you must also expect the null result. If you don't expect another type, always cast with parentheses. If it is another type, a meaningful InvalidCastException will be thrown. (Which, together with try/catch, on the other side is slower than the 'as' operator.)


dennisdoomen wrote Jun 25, 2015 at 6:35 PM

We've moved. Please post any issues at https://github.com/dennisdoomen/csharpguidelines