Search code examples
c#operators

C# { } operator


I cannot find it anywhere. Could you tell me what the expression { } means in c# or give me a link to documentation.

Here is example usage which I have found in my project:

Method(IProfileDocument profileDocument)
{
    if(profileDocument.documentId is not { } documentId
    || string.IsNullOrEmpty(documentId))
    { 
       do something...
    }
}

Solution

  • { } when used with is is an empty property pattern.

    { } is basically equivalent to != null

    Read https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns#property-pattern