Why does Boolean not throw a StackOverflowException?

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

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

why does it not throw a StackOverflowException?


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

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

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

As .NET Framework users that build on the Common Type System, we simply speak of them as being the same because, in our case, the C# compiler treats the "bool" keyword as an alias for the System.Boolean type that you see implemented in mscorlib.dll.

链接地址: http://www.djcxy.com/p/87646.html

上一篇: 这将成为IDisposable的有效基类吗?

下一篇: 为什么布尔值不抛出StackOverflowException?