I have often wondered which is the better way of checking the type of an object before carrying out an operation.
I could use the 'is' operator:
if(obj is MyClass){
var tObj = obj as MyClass;
}
Or I could use the 'as' operator and test for null:
var tObj = obj as MyClass;
if(tObj != null){
}
Is one preferable to the other? Is one way quicker? Does it matter?