Skip to main content
Post Made Community Wiki by CommunityBot
Source Link
Mike Stone
  • 44.7k
  • 30
  • 116
  • 140

I didn't know the "as" keyword for quite a while.

MyClass myObject = (MyClass) obj;

vs

MyClass myObject = obj as MyClass;

The second will return null if obj isn't a MyClass, rather than throw a class cast exception.