6

为什么在其源代码Int32中使用?在 C# 中不等于?那么原始源代码是干什么用的呢?我很困惑..intInt32intint

[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

4

1 回答 1

7

int, booletc 只是内置类型的别名,例如Int32Boolean。它们是速记,所以使用它们是有意义的。即使在他们自己的定义中。

别名是内置在编译器中的,因此不存在必须在可访问Int32之前进行编译的“鸡和蛋”情况。int没有“原始源代码” int。“源”用于Int32CLR 中内置的功能(用于处理原语)和框架(用于定义操作这些原语的功能),并在这些功能之间共享。正如对重复问题的回答所解释的那样,来源Int32不是类型本身的有效定义;这是内置在 CLR 中的。因此,编译器必须伪造int该文件中通常非法的使用,以允许该Int32类型具有功能。

于 2015-06-08T10:55:32.290 回答