I code therefore I am.

May 5, 2009 at 3:51pm
0 notes
Comments (View)
home

Tags:
CSharp  

Safe Casting

Use the as keyword.

MyClass castedObject = obj as MyClass;

This won’t throw a class cast exception. Instead, castedObject will return null if obj isn’t a MyClass.

blog comments powered by Disqus