Possible Duplicate:
casting vs using the ‘as’ keyword in the CLR
hi,
can somebody please tell me what is the difference between the following two statements, because both of them give me the same results. Also i want to know which is better.
Label lblSome = e.Item.FindControl("lblMyLable") as Label;
&&
Label lblSome = (Label)e.Item.FindControl("lblMyLable");
thank you so much.
aschecks if it can cast it, if it can’t, it sets lblSome to null. Normal casting,(Label), doesn’t do that check for you, just gives you anInvalidCastExceptioninstead. However,asdoesn’t work with non-nullable structs.