Why does Int32 use int in its source code? Doesn't Int32 equal int in C#? So what is the original source code for int? I'm confused..
[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);
...
}
there is the same issue between Boolean and bool too.
int,booletc are simply aliases for builtin types likeInt32andBooleanrespectively. They are shorthand, so it makes sense to use them. even in their own definitions.The aliases are built into the compiler, so there is no "chicken and egg" situation of
Int32having to be compiled beforeintis accessible. There is no "original source code" forint. The "source" is forInt32and is shared between functionality built into the CLR (for handling the primitives) and the framework (for defining functionality for manipulating those primitives). As this answer to a duplicate question explains, the source forInt32isn't a valid definition of the type itself; that's built into the CLR. As such, the compiler has to fudge the normally illegal use ofintwithin that file in order to allow theInt32type to have functionality.