?? not only a way to say I'm confused
- Posted: Sep 27, 2007 at 7:54AM
- 2 comments
Loading user information from Channel 9
Something went wrong getting user information from Channel 9
Loading user information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Scott Guthrie has a great post about question marks and LINQ. Well, actually, it is about the c# null coalescing operator, ??. So what does the ?? operator do? It checks a value and if null, put in something different.
string foo = arg; if( foo == null) foo = "bar";
A new possible way using ??:
string foo = arg ?? "bar";
What is even neater is you can chain values together to provide fallback.
string item = DBValue ?? ConfigValue ?? "SomeOtherValue";
Scott then goes on and demonstrates how to use this operator with LINQ. He also promised to show how to do something similar with the LINQ to XML Literal support in VB.