Friday, September 9, 2011

coercion operator in C# ??

Our subject is foo below. If it isn't null then foo just stays as foo. Otherwise, foo gets set to new List<Bar>();

foo = foo ?? new List<Bar>();

 
 

Is this the coercion operator?? (note the pun of the double question marks)

UPDATE on 3/13/2012: This operator is called the null-coalescing operator.

No comments:

Post a Comment