Why does `Int32` use` int` in its source code?

Why Int32 use int in its source code ? Does Int32 int match in c #? So what is the 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 problem between Boolean and bool too.

+6
source share
1 answer

int , bool , etc. are simply aliases for built-in types such as Int32 and Boolean respectively. They are abbreviated, so it makes sense to use them. even in their own definitions.

Aliases are built into the compiler, so there is no Int32 chicken and egg situation that must be compiled before an int is available. There is no source code for int . The "source" is intended for Int32 and is divided between the functionalities built into the CLR (for processing primitives) and the framework (for defining the functionality for managing these primitives). As this answer to a duplicate question is explained , the Int32 source is not a valid definition of the type itself; which is built into the CLR. Thus, the compiler must lure out the usually illegal use of int inside this file in order to be able to use the Int32 type.

+7
source

Source: https://habr.com/ru/post/988714/


All Articles