Why doesn't Boolean throw a StackOverflowException?

I found the Boolean source code at http://referencesource.microsoft.com/#mscorlib/system/boolean.cs :

public struct Boolean { ... private bool m_value; ... } 

why doesn't it throw a StackOverflowException?

+7
c #
source share
1 answer

The reason for this is because the types bool and System.Boolean are actually different.

The primitive type bool is a built-in type that stores 1 byte.

The System.Boolean type serves as an object wrapper for a primitive type and implements the IComparable and IConvertable interfaces. This wrapper is implemented to represent the primitive type accurately so that they can become logically interchangeable.

As users of the .NET Framework who use the Common Type System, we just talk about them as the same, because in our case the C # compiler treats the keyword β€œbool” as an alias for the type System.Boolean, which you see what is implemented in mscorlib.dll.

+4
source share

All Articles