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

标签 c# .net performance clr type-systems

为什么 .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/

相关文章:

c# - 在 session 中存储散列密码是不可取的吗?

c# - 如何在 Datagridview C# 中为特定列设置列标题文本

java - 以最高效的方式使用 JDBC 获取 MySQL 查询返回的结果计数

performance - 64 位和内存带宽

.net - 我可以改进这段代码来绘制轮廓文本吗

c++ - Direct2D 渲染 CPU 使用率

c# - 在 C# 中解析自定义文件

c# - 使用 DirectoryServices.AccountManagement 从 OU 获取组

c# - 如何更改正则表达式以处理数字后的 _ 符号?

.net - NEST 7:如何获取每个文档的出现编号?