Non-nullable reference type: why is my object considered nullable by the compiler?

后端 未结 2 810
北荒
北荒 2021-01-19 05:39

I\'ve a project on which I enabled the new Nullable reference type feature

 enable
<         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-19 06:31

    Check out the specification on nullable reference types. It states that var infers an annotated type for reference types.

    The part under the heading nullable implicitly typed local variables reads:

    var infers an annotated type for reference types. For instance, in var s = ""; the var is inferred as string?.

提交回复
热议问题