C# Int32: m_value

前端 未结 3 1200
北荒
北荒 2020-12-11 21:31

After reading a bit about the Int32 struct in C#, I realized that int and Int32 are synonymous. In the source code of Int32 struct, th

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 21:49

    It's rather hard to follow what's going on when reading the source of the core framework.

    "how the value gets stored in m_value when we give int i=7;"

    Firstly, when the C# compiler sees int, it just pretends you said System.Int32 instead (*). Similarly when it sees 7, it says "aha! That's an integer literal. I'll store it in a System.Int32". So then it creates the variable i (of the right type), and initializes it with the value it created.

    (*) That means that the source http://referencesource.microsoft.com/#mscorlib/system/int32.cs,225942ed7b7a3252 has:

    public struct Int32 : *various bases*
    {
        internal Int32 m_value;
    

    ... which is ever so slightly confusing (and wouldn't normally be legal).

提交回复
热议问题