在 C# 中,where T : class?
是什么意思(注意类约束末尾的问号)
例如
public IList<T> DoThis<T>() where T : class?
最佳答案
?
附加到 C# 中的类型(从版本 8 开始支持)意味着它是一个 nullable reference type . class?
意味着调用代码必须传入一个类型参数,它是 class
, 并且可以为空。
例如,DoThis<string?>(someNullableString)
已验证。它也可以用不可为空的版本调用,例如DoThis<string>(someNonNullableString)
.
关于c# - 在 C# 中 'where T : class?' 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60557094/