Non-nullable string type, how to use with Asp.Net Core options

前端 未结 1 1914
傲寒
傲寒 2021-01-04 07:26

MS states Express your design intent more clearly with nullable and non-nullable reference types.

My intent is to express, that properties Issuer and <

1条回答
  •  清酒与你
    2021-01-04 08:07

    As far as the compiler knows, it has not been initialized and can be null. Use the !(null-forgiving operator) as a last resort (and leave a comment explaining why you used !.

    // This should be set by the options binding
    public string Issuer { get; set; } = null!; 
    

    0 讨论(0)
提交回复
热议问题