Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#中的int是什么?_C#_Value Type_Reference Type - Fatal编程技术网

c#中的int是什么?

c#中的int是什么?,c#,value-type,reference-type,C#,Value Type,Reference Type,什么是C中的int?它是关键字还是从system.ValueTypes派生的类?如果它是一个关键字,那么下面几行如何编译 int i = new int(); // If int is not a class then how does it have a default constructor Console.WriteLine(i.ToString()); // If int is not a class then how does it have member functions 如果

什么是C中的
int
?它是关键字还是从system.ValueTypes派生的类?如果它是一个关键字,那么下面几行如何编译

int i = new int(); // If int is not a class then how does it have a default constructor

Console.WriteLine(i.ToString()); // If int is not a class then how does it have member functions
如果
int
是一个类,那么为什么不必总是用
new
初始化它呢?下面这行代码是如何编译的

int i = 8;

int
是一个关键字,它是值类型(
struct
System.Int32
的别名

作为常规值类型,我相信它的继承是
System.Object
->
System.ValueType
->
System.Int32


因为
int
有文字符号,就像字符串和其他数字类型一样,您可以创建它的实例,而无需
new

int
是值类型(
struct
System.Int32
的别名关键字

作为常规值类型,我相信它的继承是
System.Object
->
System.ValueType
->
System.Int32

因为
int
有文字符号,就像字符串和其他数字类型一样,您可以在不使用
new
的情况下创建它的实例。int是CTS type
System.Int32
的别名

阅读Eric Lippert发布的SO答案-

int是CTS类型的别名
System.Int32


阅读Eric Lippert发布的SO答案-

用代码解释代码:

Console.WriteLine(typeof(int) == typeof(Int32)); // Outputs: True
Console.WriteLine(typeof(int).Name); // Outputs: Int32

用代码解释代码:

Console.WriteLine(typeof(int) == typeof(Int32)); // Outputs: True
Console.WriteLine(typeof(int).Name); // Outputs: Int32

谁说“结构”或“值类型”不能有方法?这是一些Java废话:)
int
System.Int32
,它是一种
struct
-类型。(为了使生活更简单,编译器知道各种“文字”构造,如整数、浮点值和字符串。但是,它是一个固定的集合。例如,GUID没有“文字”,因此需要
new GUID(string)
。)所有值类型都可以有方法,Java是一个愚蠢的例外。
inti=8
编译的原因与
string foo=“bar”
编译的原因相同
8
是类型
int
的文本,就像
“bar”
是类型
字符串的文本一样。如果int是结构
系统的别名。Int32
,那么它如何从
系统继承。Object
类???@user1232138每个
结构
都是
值类型
的子类型,
值类型
对象
的子类型。与
不同,不能使用
结构
指定其他子类型(尽管可以指定接口)。这就是在C#/CLR中定义类型树的方式。当然,这不是全部<代码>对象x=1
“框”(关键字)例如
int
值。谁说“结构”或“值类型”不能有方法?这是一些Java废话:)
int
System.Int32
,它是一种
struct
-类型。(为了使生活更简单,编译器知道各种“文字”构造,如整数、浮点值和字符串。但是,它是一个固定的集合。例如,GUID没有“文字”,因此需要
new GUID(string)
。)所有值类型都可以有方法,Java是一个愚蠢的例外。
inti=8
编译的原因与
string foo=“bar”
编译的原因相同
8
是类型
int
的文本,就像
“bar”
是类型
字符串的文本一样。如果int是结构
系统的别名。Int32
,那么它如何从
系统继承。Object
类???@user1232138每个
结构
都是
值类型
的子类型,
值类型
对象
的子类型。与
不同,不能使用
结构
指定其他子类型(尽管可以指定接口)。这就是在C#/CLR中定义类型树的方式。当然,这不是全部<例如,code>object x=1
“box”(关键字)值
int
。如果int是结构
System.Int32
的别名,那么它如何从
系统继承。object
类??如果int是结构
System.Int32
的别名,那么它如何从
系统.Object
类继承?如果int是结构
系统.Int32的别名,那么它如何从
系统.Object
类继承???@user1232138:所有值类型都将
系统.Object
作为间接基类。如果int是结构
系统.Int32的别名,那么它如何从
System.Object
类中继承???@user1232138:所有值类型都将
System.Object
作为间接基类。