gpt4 book ai didi

c# - 为什么 .NET 中存在 null?

转载 作者:IT王子 更新时间:2023-10-29 04:03:02 24 4
gpt4 key购买 nike

为什么 .NET 中的值可以为空?这是否优于保证所有内容都有值且没有任何内容为空?

有人知道这些方法分别叫什么吗?

无论哪种方式,我对此都不是很了解,但是就简单性而言,不会对所有事物都有值(value)使事情变得更容易,即消除空检查,并能够编写更简化的算法,而这些算法没有分支支票。

每种风格在性能、简单性、并行性、面向 future 等方面的优缺点是什么。

最佳答案

我们有Tony Hoare ,一位在 Algol 上工作的早期先驱,对此表示感谢。他很后悔:

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

我认为十亿是一个低球数。


更新:C# 版本 8 和 .NETCore 对此问题有一个不错的解决方案,查看 non-nullable reference types .

关于c# - 为什么 .NET 中存在 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5149074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com