为什么可空<诠释>不能编译,但诠释?确实没有'使用系统;“ [英] Why Nullable<int> can't compile but int? does without 'using System;'

查看:153
本文介绍了为什么可空<诠释>不能编译,但诠释?确实没有'使用系统;“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在净2,code:

namespace ns
{
    class Class1
    {
        Nullable<int> a;
    }
}

无法编译,并给出错误:

does not compile and gives the error:

的类型或命名空间名称可空'找不到(是否缺少using指令或程序集引用?)

The type or namespace name 'Nullable' could not be found (are you missing a using directive or an assembly reference?)

它缺少使用系统; 但这code:

namespace ns
{
    class Class1
    {
        int? a;
    }
}

编译。

有人可以解释,为什么?

Can somebody explain why?

推荐答案

我相信INT?是一个别名

I believe that int? is an alias for

System.Nullable<System.Int32>

由于完整的类型名称指定,没有理由增加使用指令。

Because the full type name is specified, there are no reason to add a using directive.

这篇关于为什么可空&LT;诠释&GT;不能编译,但诠释?确实没有'使用系统;“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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