Difference between "?" and "??" operators in C#

by Waqas 5/11/2008 2:09:00 PM

Conventional Code:

   string f(string inputString)
    {
        if (inputString != null)
            return inputString;
        else
            return "";
    }

Better code with operator ?

    string f(string inputString)
    {
        return (inputString != null) ? inputString : "";
    }

Much better code with operator ??

    string f(string inputString)
    {
        return (inputString) ?? "";
    }

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Better Coding

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading




Tags

© Copyright Beyond Web Logs.


Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in