the internals of System.String

前端 未结 4 1808
不思量自难忘°
不思量自难忘° 2021-02-13 08:53

I used reflection to look at the internal fields of System.String and I found three fields:

m_arrayLength

m_stringLength

m_firstChar

I don\'t

4条回答
  •  甜味超标
    2021-02-13 09:30

    Much of the implementation of System.String is in native code (C/C++) and not in managed code (C#). If you take a look at the decompiled code you'll see that most of the "interesting" or "core" methods are decorated with this attribute:

    [MethodImpl(MethodImplOptions.InternalCall)]
    

    Only some of the helper/convenience APIs are implemented in C#.

    So where are the characters for the string stored? It's top secret! Deep down inside the CLR's core native code implementation.

提交回复
热议问题