null-coalescing operator or conditional operator

Posted by rkrauter on Stack Overflow See other posts from Stack Overflow or by rkrauter
Published on 2010-04-24T15:04:20Z Indexed on 2010/04/24 15:13 UTC
Read the original article Hit count: 426

Filed under:

Which coding style do you prefer:

object o = new object();
//string s1 =  o ?? "Tom"; // Cannot implicitly convert type 'object' to 'string' CS0266
string s3 = Convert.ToString(o ?? "Tom");
string s2 = (o != null) ? o.ToString() : "Tom";

s2 or s3?

Is it possible to make it shorter? s1 does not obviously work.

© Stack Overflow or respective owner

Related posts about c#