By paul_houle
via gen5.info
Published: Jun 16 2008 / 11:57
C# offers two casting operators: the prefix-cast and the as-cast. Although the two operators compile to different op-codes in the CLR, the practical difference between them is in how they handle failed casts. Prefix-cast throws an exception on cast failure, while as-cast returns null. It’s easier to implement correct error handling when you use prefix cast, because it doesn’t require manual checks for null values that can cause problems in distant parts of your program. Prefix-cast should be the default cast operator on your fingertips, that you use for everyday situations
Comments
SilvioSuller replied ago:
to basic
Voters For This Link (10)
Voters Against This Link (1)