I was wondering what is the best method for Casting objects for C #:
MyClassName test = (MyClassName)object; MyClassName test = object as MyClassName;
I already know that if you do the first method, you get an exception, and the second method sets the test to null. However, I was wondering why one over the other? I see the first way a lot, but I like the second way, because then I can check for zero ...
If there is no better way to do this, what are the recommendations for using this or that method?
source share