为什么`Int32`在其源代码中使用`int`?

Moh*_*deh 7 c# int32 reference-source

为什么在源代码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);

        ...
    }
Run Code Online (Sandbox Code Playgroud)

之间存在相同的问题Booleanbool太多.

Dav*_*rno 7

int,bool等只是用于内建类型,如别名Int32Boolean分别.它们是速记,因此使用它们是有意义的.甚至在他们自己的定义中.

别名内置于编译器中,因此Int32int访问之前不必编译"鸡和鸡蛋"的情况.没有"原始源代码" int."源"用于Int32CLR内置的功能(用于处理基元)和框架(用于定义操作这些基元的功能)之间共享.正如对重复问题的答案所解释的那样,源Int32不是类型本身的有效定义; 这是内置于CLR中的.因此,编译器必须捏造该int文件中的正常非法使用,以便允许该Int32类型具有功能.

  • 这根本不回答这个问题. (5认同)
  • @DavidArno我在发表评论后对你的答案进行了重大修改(可以从评论时间和编辑时间进行验证).你现在回答这个问题.不像Eric Lippert在链接问题中那么好,但它比以前好多了. (2认同)