什么是null文本的类型? [英] What is the type of null literal?

查看:144
本文介绍了什么是null文本的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ð 的耳朵全部,我不知道什么是的字面的类型C#?

Dear all, I wonder what is the type of null literal in C#?

在Java中,文字的是特殊的 null类型

In Java, the null literal is of the special null type:

还有一个特殊的 null类型的,的前pression ,它没有名字的类型。因为空类型没有名字,它是不可能的声明空类型的变量或强制转换为null类型。空引用是null类型的前pression唯一可能的值。空引用总是可以被转换为任何引用类型。

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type.

在C ++ 11,有 nullptr (老哥们推荐的版本 NULL ),这的类型是的std :: nullptr_t

In C++11, there is nullptr (the recommended version of the old buddy NULL), which is of type std::nullptr_t.

我搜索MSDN关于C#,但规范似乎没有说任何东西这一点。

I searched MSDN about C#, but the specification doesn't seem to say anything about that.

推荐答案

根据该的 ECMA C#语言规范

9.4.4.6 null文本:

9.4.4.6 The null literal:

一空文字的类型是null类型(§11.2.7)。

The type of a null-literal is the null type (§11.2.7).

11.2.7空类型:

11.2.7 The null type:

空文字(§9.4.4.6)的计算结果为空值,这是用来   来表示一个参考不指向任何物体或阵列,或   没有价值的。空型具有单一值,这是   空值。因此,一个前pression类型为null类型可以   评价只对空值。有没有办法明确写入   空型的,因此,没有办法用它在一个声明的类型。   此外,null类型永远不能类型推断出的一种类型的   参数(§25.6.4)

The null literal (§9.4.4.6) evaluates to the null value, which is used to denote a reference not pointing at any object or array, or the absence of a value. The null type has a single value, which is the null value. Hence an expression whose type is the null type can evaluate only to the null value. There is no way to explicitly write the null type and, therefore, no way to use it in a declared type. Moreover, the null type can never be the type inferred for a type parameter (§25.6.4)

因此​​,要回答你的问题,空是它自己的类型 - null类型。

So to answer your question, null is it's own type - the null type.

虽然这很奇怪它怎么没有在 C#4.0语言规范或<一href="http://www.google.co.uk/url?sa=t&rct=j&q=c%23%203.0%20language%20specification&source=web&cd=1&ved=0CB0QFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F3%2F8%2F8%2F388e7205-bc10-4226-b2a8-75351c669b09%2Fcsharp%2520language%2520specification.doc&ei=J3XJTp7XDYvw8QO8-7Bs&usg=AFQjCNGXik09_Rn-k0FGHG-A6v1EX3RLyA">C# 但提到在C#3.0 ,在<一的概述3.0语言规范HREF =htt​​p://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf> ECMA C#语言规范和<一href="http://www.google.co.uk/url?sa=t&rct=j&q=c%23%202.0%20spec&source=web&cd=1&ved=0CCAQFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F9%2F8%2Ff%2F98fdf0c7-2bbd-40d3-9fd1-5a4159fa8044%2Fcsharp%25202.0%2520specification_sept_2005.doc&ei=8XTJTsnfNpPn8QOixr14&usg=AFQjCNEFwD5nwtV7dLgz3PiYnF19ZkMB-Q&cad=rja">C# 2.0语言规范。

Although it's odd how it's not mentioned in the C# 4.0 language specification or the C# 3.0 language specification but is mentioned in the overview of C# 3.0, the ECMA C# language specification and the C# 2.0 language specification.

这篇关于什么是null文本的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆