What is the maximum possible length of a .NET string?

后端 未结 8 1654
梦毁少年i
梦毁少年i 2020-11-22 02:48

What is the longest string that can be created in .NET? The docs for the String class are silent on this question as far as I can see, so an authoritative answe

8条回答
  •  无人及你
    2020-11-22 03:27

    The theoretical limit may be 2,147,483,647, but the practical limit is nowhere near that. Since no single object in a .NET program may be over 2GB and the string type uses UTF-16 (2 bytes for each character), the best you could do is 1,073,741,823, but you're not likely to ever be able to allocate that on a 32-bit machine.

    This is one of those situations where "If you have to ask, you're probably doing something wrong."

提交回复
热议问题