Chaining the C# ?? Operator

Posted by: Rick Strahls WebLog, on 24 Jan 2008 | View original | Bookmarked: 0 time(s)

C# 2.0 has a nice ?? operator that works as a shortcut for: string value1 = null;string value2 = "Test1";string result = value1 != null ? value1 : value2;    which causes result containing Test1 or the second value. In C# you can shortcut this special null comparison case with the new ??: string result = value1 ?? value2; which is a little easier to write. This is probably not news to you, but what's really useful is that you can chain these operators together so you can do a whole...

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: C# | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 928 | Hits: 71

Similar Posts

  • Select Many: Reactive Extensions Mother Of All Operators [Chaining] more
  • Programmer Symbology more
  • Filtering with string parameter that allows free user input more
  • What I learned about PHP today more
  • An Extensive Examination of LINQ: Grouping and Joining Data more
  • An Extensive Examination of LINQ: The Standard Query Operators more
  • An Extensive Examination of LINQ: The Ins and Outs of Query Operators more
  • An Extensive Examination of LINQ: Lambda Expressions and Anonymous Types more
  • An Extensive Examination of LINQ: Extension Methods, Implicitly Typed Variables, and Object Initializers more
  • Divided We Stand: The SQL of Relational Division more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD