C# { } 运算符

Ell*_*bar 3 c# operators

我在任何地方都找不到它。您能否告诉我表达式{ }在 C# 中的含义,或者给我一个文档链接。

这是我在项目中找到的示例用法:

Method(IProfileDocument profileDocument)
{
    if(profileDocument.documentId is not { } documentId
    || string.IsNullOrEmpty(documentId))
    { 
       do something...
    }
}
Run Code Online (Sandbox Code Playgroud)

Pig*_*let 5

{ }与 一起使用时is是一个空属性模式。

{ }基本上相当于!= null

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