-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,121
  • 3
  • 24
  • 32
Freddyerf
  • 67
  • 6

1 Answers1

2

It is a null conditional operator.

https://docs.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
  • 5,892
  • 2
  • 22
  • 18