为什么Int32在其源代码中使用int?Int32在C#中不等于int吗?那么,int的原始源代码是什么呢?我很困惑..。
[Serializable]
[System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
[System.Runtime.InteropServices.ComVisible(true)]
#if GENERICS_WORK
public struct Int32 : IComparable, IFormattable, IConvertible
, IComparable<Int32>, IEquatable<Int32>
/// , IArithmetic<Int32>
#else
public struct Int32 : IComparable, IFormattable, IConvertible
#endif
{
internal int m_value; // Here????
public const int MaxValue = 0x7fffffff;
public const int MinValue = unchecked((int)0x80000000);
...
}Boolean和bool之间也存在同样的问题。
发布于 2015-06-08 10:55:32
int、bool等只是Int32和Boolean等内置类型的别名。它们是速记,所以使用它们是有意义的。即使在他们自己的定义里。
别名被内置到编译器中,因此在访问Int32之前不需要编译int的“鸡和蛋”情况。int没有“原始源代码”。“源”用于Int32,并在内置于CLR中的功能(用于处理原语)和框架(用于定义操作这些原语的功能)之间共享。作为这个对重复问题的回答解释了,Int32的源代码不是类型本身的有效定义;它是内置在CLR中的。因此,编译器必须伪造该文件中通常非法使用的int,以便允许Int32类型具有功能。
https://stackoverflow.com/questions/30707278
复制相似问题