-2

I know this may be a pretty basic question, but anyway. What does the ? means when before a method. i.e.:

I have a list property:

public List<MsisdnDto> NumbersMsisdn { get; set; }

And a boolean method:

public bool Success()
{
    return NumbersMsisdn?.Count() > 0;
}

I want to know exactly what does that ? do.

maccettura
  • 10,514
  • 3
  • 28
  • 35
Freddyerf
  • 87
  • 7

1 Answers1

4

It is a null conditional operator.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators

If the object on which you are calling the method is null, the method is not called and null is returned.

Brian Rudolph
  • 6,142
  • 2
  • 23
  • 19