C# creating a non-nullable string. Is it possible? Somehow?

后端 未结 8 981
感情败类
感情败类 2021-01-11 10:05

So you can\'t inherit string. You can\'t make a non-nullable string. But I want to do this. I want a class, let\'s call it nString that returns a d

8条回答
  •  无人及你
    2021-01-11 10:29

    No, you cannot do this.

    The only way to create a non-nullable type is to declare a struct - structs, however, cannot inherit or be inherited from.

    Using properties as you are is most likely the best way, or null-coalescing during deserialization as previously suggested, but C# is simply designed to handle null values.

提交回复
热议问题