当前位置:网站首页>c# 解决CS8602告警 解引用可能出现空引用

c# 解决CS8602告警 解引用可能出现空引用

2022-08-10 01:18:00 ou.cs

在这里插入图片描述
!null 容忍操作符(null-forgiving operator)

官方文档:! (null-forgiving) operator (C# reference) The compiler warns
that you may be dereferencing null when you write the property
message.Length because its static analysis determines that message may
be null. You may know that IsNotNull provides a null check, and when
it returns true, the null-state of message should be not-null. You
must tell the compiler those facts. One way is to use the null
forgiving operator, !. You can change the WriteLine statement to match
the following code:

它的主要作用就是告诉编译器,变量不可能为 null。
在这里插入图片描述

原网站

版权声明
本文为[ou.cs]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44291381/article/details/126176463