基本类型在.net中 [英] Primitive types in .net

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

问题描述

在.NET中,AIUI INT 是只是语法糖 System.Int32 ,这是一个<$ C 。$ C>结构

In .net, AIUI int is just syntactic sugar for System.Int32, which is a struct.

csharp> typeof(System.Int32).IsPrimitive 
true
csharp> typeof(System.Int32).Equals(typeof(int))
true



我看源:

I see in the source:

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 参照自己? ?那么,如何才能避免循环定义然后

That System.Int32 is just defined with reference to a member m_value that is itself an int - how does that work? Surely we're defining int with reference to itself? So how do we avoid circular definition then?

推荐答案

有在迪信的博客文章的了解.NET基本类型的。

There is an excellent explanation in Dixin's blog article Understanding .NET Primitive Types.

答案可以在生成的IL被发现。他以下问题实际上是回答你的问题:

The answer can be found in the generated IL. His following question is actually the answer to your question:

那么,什么是INT32之间(IL),INT(C#)和系统的关系.Int32(C#)?

So what is the relationship among int32 (IL), int (C#) and System.Int32 (C#)?

在IL可以发现,在 INT 里面的结构是:

In the IL can be found that the int inside the struct is:

.field assembly int32 m_value

INT32 确实存在之外.NET和是在.NET INT 在装配的实际表示。

So that int32 actually exists outside .NET and is the actual representation of the .NET int in assembly.

这篇关于基本类型在.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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