Learn‎ > ‎.NET‎ > ‎

C#

Learn C#

  • Code Better Null Coalescing Operator (??) This one is such an elegant little operator that can be extremely useful in some situations.  How often do you have a variable that you want to use the value of, but if that value is null you want to substitute a default value?  For example, say you wanted to assign a string to a variable, but if that string is null you want the empty string instead? You could, of course, write an if statement: 1: string name = value; 2:  3: if (value == null) 4: { 5: name = string.Empty; 6: } Source:http://geekswithblogs.net/BlackRabbitCoder/archive/2010/08/26/c.net-five-little-wonders-that-make-code-better-1-of.aspx
    Posted Nov 24, 2010, 11:00 AM by Shaukat Mahmood Ahmad
Showing posts 1 - 1 of 1. View more »

Subpages (1): Tutorials
Comments