Help me figure this out, I don't know what that line means in the code.



  • var someVariable = someClassInstance?.CallMethod();
    

    What is this sign of the question and how can it be applied in practice?



  • ?. - it's a new operator at C# 6.0. It is called null propagation operator (I don't know how Russian will be). This is...

    var someVariable = someClassInstance?.CallMethod();
    

    a short version of this code:

    var someVariable = someClassInstance == null ? null : someClassInstance.CallMethod();
    

    It also provides https://docs.microsoft.com/ru-ru/dotnet/csharp/language-reference/operators/member-access-operators#thread-safe-delegate-invocation ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2