Which kind of cast should you use in C#?(gen5.info)
submitted by
paul_houle(435) 3 years, 11 months ago
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 — reserve as-cast for special cases where performance matters. read more...
|category: C#
|Views: 493
tags:
C# another
Everyones tags:
Your Tags: