Why is “null” present in C# and Java?

前端 未结 25 1977
别那么骄傲
别那么骄傲 2020-11-29 22:09

We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.

Is there a reason why \"null\" has even been included in the l

25条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 22:34

    After all, if there were no "null", I would have no bug, right?

    The answer is NO. The problem is not that C# allows null, the problem is that you have bugs which happen to manifest themselves with the NullReferenceException. As has been stated already, nulls have a purpose in the language to indicate either an "empty" reference type, or a non-value (empty/nothing/unknown).

提交回复
热议问题