在我看来,确实没有任何保证一个不可为空的变量绝不会为null。想象一下,如果我有一个类,其中有一个属性是不可为空的:
public class Foo
{
public Foo(string test)
{
Test = test;
}
public string Test {get;set;}
}
现在看起来好像它现在不能为空。但是如果我们用另一个不使用可空上下文的库引用此类,它可以发送null值。
这正确吗?还是可能有一些运行时检查可以确保这一点吗?
public void Foo(string test){...}
还是public Foo(string test){...}
? - huMpty duMpty