在.net中,AIUI int
只是System.Int32
的语法糖,struct
。
csharp> typeof(System.Int32).IsPrimitive
true
csharp> typeof(System.Int32).Equals(typeof(int))
true
我在源码中看到:
https://github.com/mono/mono/blob/master/mcs/class/corlib/System/Int32.cs http://referencesource.microsoft.com/#mscorlib/system/int32.cs
System.Int32
只是引用成员 m_value
定义的,它本身是一个 int
- 它是如何工作的?我们肯定是在引用自身定义 int
吗?那么我们如何避免循环定义呢?
最佳答案
地欣的博文中有很好的解释Understanding .NET Primitive Types .
答案可以在生成的 IL 中找到。他的以下问题实际上是您问题的答案:
So what is the relationship among int32 (IL), int (C#) and System.Int32 (C#)?
在IL中可以发现struct
里面的int
是:
.field assembly int32 m_value
因此 int32
实际上存在于 .NET 之外,并且是 .NET int
在程序集中的实际表示。
关于c# - .net 中的原始类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25009327/