在C#8.0中调用方法之前,感叹号是什么意思? [英] What does exclamation mark mean before invoking a method in C# 8.0?
本文介绍了在C#8.0中调用方法之前,感叹号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了一个看似用C#8.0版编写的代码.在代码中,在调用方法之前有一个感叹号.这部分代码是什么意思,最重要的是,它的用途是什么?
I have found a code written in C# seemingly version 8.0. In the code, there is an exclamation mark before invoking a method. What does this part of the code mean, and above all, what are its uses?
var foo = Entity!.DoSomething();
推荐答案
这将是空宽容运算符.
它告诉编译器这不是null,请相信我",因此它不会针对可能的null引用发出警告.
This would be the null forgiving operator.
It tells the compiler "this isn't null, trust me", so it does not issue a warning for a possible null reference.
在这种特殊情况下,它告诉编译器 Entity
不为null.
In this particular case it tells the compiler that Entity
isn't null.
这篇关于在C#8.0中调用方法之前,感叹号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文