Why does null exist in .NET?

前端 未结 11 1572
醉酒成梦
醉酒成梦 2020-12-24 06:04

Why can values be null in .NET? Is this superior to having a guarantee where everything would have a value and nothing call be null?

Anyone knows what each of these

11条回答
  •  孤城傲影
    2020-12-24 06:33

    Well, values (value-type vars) can only be null since the nullable types were introduced in Fx2.

    But I suppose you mean:

    Why can references be null ?

    That is part of the usefulness of references. Consider a Tree or LinkedList, they would not be possible (unable to end) without null.

    You could come up with many more examples, but mainly null exists to model the concept of 'optional' properties/relationships.

提交回复
热议问题