[英]how i can fix following nullrefernce ? and also how can I turn off nullrefernce (from <propertygroup>)?
public class BlockChain
{
public IList<Block>Chain{ get; set; }
}
Non-nullable property 'Chain' must contain a non-null value when exiting constructor.退出构造函数时,不可为 null 的属性“Chain”必须包含非空值。 Consider declaring the property as nullable.
考虑将该属性声明为可为空。
Not sure what project you are writing but you could do:不确定你在写什么项目,但你可以这样做:
<Nullable>disable</Nullable>
in.csproj file<Nullable>disable</Nullable>
#nullable disable
in class#nullable disable
Chain
as public IList<Block> Chain{ get; set; } = new NameOfClassThatImplementsInterface();
Chain
设置为public IList<Block> Chain{ get; set; } = new NameOfClassThatImplementsInterface();
public IList<Block> Chain{ get; set; } = new NameOfClassThatImplementsInterface();
(recommended) Chain
as public IList<Block>? Chain{ get; set; }
Chain
设置为public IList<Block>? Chain{ get; set; }
public IList<Block>? Chain{ get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.