Every Developer has his/her own standards. Some developers like to <type>.TryParse()
, some developers like to cast using (type)object;
, and some developers love using the keywords instead.
I noticed a hiccup with the 'as'
operator - you cannot use it to perform conversions between non-nullable value types. I read the documentation on MSDN on the as Keyword and they also explain it as "You can use the as operator to perform certain types of conversions between compatible reference types or nullable types."
I tested this with the following:
int i = 0;
var k = i as int; //Breaks
int i = 0;
var k = i as int?; //Works
What were the reasons decided for the as
keyword to perform in this way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…