Possible Duplicate:
C# “as” cast vs classic cast
I’ve inherited some code and I see this Grid event handler. I don’t know if there’s a difference between these two statements, I wouldn’t think there is, but the fact that they are back to back in the code makes me wonder why do the same thing two ways (assuming they do the same thing). Could someone explain the difference, if any?
GridDataItem ParentItem = e.Item as GridDataItem;
GridDataItem NewRow = (GridDataItem)e.Item;
“The as operator is like a cast operation. However, if the conversion is not possible, as returns null instead of raising an exception”
“Note that the as operator only performs reference conversions and boxing conversions. The as operator cannot perform other conversions, such as user-defined conversions, which should instead be performed by using cast expressions.”
Read More