c# - .net 中的原始类型

标签 c# .net int clr primitive-types

在.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/

相关文章:

python - int() 不适用于花车?

c# - 如何使用 asp.net mvc 呈现从支付网关返回的 HTML 响应

c# - 如何使用 Entity Framework 6 通过 IN 语句执行原始 sql

c# - 将查询语法中的 LINQ 转换为 lambda 语法

c - 整数相加问题xCode

java - 为什么这两个乘法运算会给出不同的结果?

c# - 以编程方式获取 DLL 的版本号

c# - 如何从站点地图文件中获取当前页面标题?

.net - 将格式化文本复制到剪贴板,字体除外

c# - 为什么在 GetCurrent 之前调用 IEnumerator.MoveNext?