【发布时间】:2020-07-29 02:17:01
【问题描述】:
我开始在 VS19 预览版中收到这些警告,并且
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>`
<Nullable>enable</Nullable>
这是一个类的示例,它代理了很多它的方法到ImmutableList<T>:
class C<T> {
readonly ImmutableList<T> composed;
public C() => composed = ImmutableList<T>.Empty;
...
public T Find(Predicate<T> match) => composed.Find(match);
...
}
警告 CS8603:可能返回空引用。 对于
Find方法
我不明白为什么它的签名与 ImmutableList<T>.Find 相同?
解决此问题的最佳方法是什么?
【问题讨论】:
-
也许可以试试
.First()? -
@zaitsman 这将解决问题,但引入异常的可能性。
标签: c# c#-8.0 nullable-reference-types c#-9.0