If you cast with the as
keyword and the cast is not possible it returns null
.
Then in your case you call me.GetType()
with me
being null
at the moment so an exception is thrown.
If you cast like (Person) objectOfTypeThatDoesNotExtendPerson
an exception is thrown instantly at the cast.