• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅

C#中的?.和!.操作符(链接)

下面的微软官方文档介绍了C#中的?操作符

  • Generics
  • Nullable reference types (C# reference)

注意上面这个文档里面的这句话:

A variable m of type T? is considered to be non-null when you apply the null-forgiving operator, as in m!.

也就是说,如果你想强制声明一个T?对象是肯定不为null的,那么可以使用!操作符

  • Null-conditional operators ?. and ?[]
  • 12.8.8 Null Conditional Member Access

下面的微软官方文档介绍了C#中的!操作符:

  • ! (null-forgiving) operator (C# reference)
  • 12.8.9 Null-forgiving expressions

 

posted @ 2024-11-11 23:57  PowerCoder  阅读(145)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3