Coffeehouse Post

Single Post Permalink

View Thread: C# trivia question
  • User profile image

    I've been using this operator for a while, but I always thought it was syntactic sugar. Yesterday, I decided run some code through the debugger, and I was surprised to find the difference between them.

    This will invoke SomeMethod() twice:

    var someval = (SomeMethod() == null) ? String.Empty : SomeMethod();

    This will not:

    var someval = SomeMethod() ?? String.Empty;