the internals of System.String

前端 未结 4 1729
不思量自难忘°
不思量自难忘° 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:47

    I'd be thinking immediately that m_firstChar is not the first character, rather a pointer to the first character. That would make much more sense (although, since I'm not privy to the source, I can't be certain).

    It makes little sense to store the first character of a string unless you want a blindingly fast s.substring(0,1) operation :-) There's a good chance the characters themselves (that the three fields allude to) will be allocated separately from the actual object.

提交回复
热议问题