C
ChrisMiddle10
Are there serious to moderate performance issues to weigh when deciding
to use the 'is' and 'as' keywords over - let's say - more explicit
checks for null and type? Any best practices or heuristics for their
usage?
Snippet 1:
if ( obj == null && obj.GetType( ) == typeof( MyType ) )
{
MyType myType = ( MyType ) obj;
}
Snippet 2:
if ( obj is MyType )
{
MyType myType = obj as MyType;
}
Obviously, Snippet 2 is much cleaner, which I like, but am I losing
anything?
Thanks!
- Chris
to use the 'is' and 'as' keywords over - let's say - more explicit
checks for null and type? Any best practices or heuristics for their
usage?
Snippet 1:
if ( obj == null && obj.GetType( ) == typeof( MyType ) )
{
MyType myType = ( MyType ) obj;
}
Snippet 2:
if ( obj is MyType )
{
MyType myType = obj as MyType;
}
Obviously, Snippet 2 is much cleaner, which I like, but am I losing
anything?
Thanks!
- Chris