C# { } 运算符

标签 c# operators

我到处都找不到。你能告诉我表达式 { } 在 C# 中的含义吗?或者给我一个文档链接。

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

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

最佳答案

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

{ } 基本上等同于 != null

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

关于C# { } 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73698025/

相关文章:

C# - 迭代在没有显式 IEnumerable 的情况下工作

c# - 如何在 C# .NET 中像 Java 代码一样加密

swift - 组合使用自定义运算符

php - PHP中这两个比较有什么区别?

c# - 程序化城市建模 - 多边形分割(也许是更好的想法?)

c# - 键值对的正则表达式

c# - 可以从 javascript/jquery 获取返回 url 吗?

c# - 增量运算符如何与数组一起使用?

c++ - 低级 C++ 运算符工作

c++ - 什么是 C++ 中的 <=> ("spaceship",三向比较)运算符?