Hello everyone, I have an interesting article on the Internet.ArticleTherefore, reprinted the following:
Web site: http://qinghua.me/max-length-of-string-in-c-sharp/
The maximum length of string in C #
Posted on 2012/04/11 by Qinghua
You cannot create a string with a length greater than Int. maxvalue. Naturally, I got a question: how many strings can be reached in C?
I found the relevant information (stackoverflow is really a paradise for codoon). The result is:
1. We use string. length to read the string length, which is of the int type. Therefore, int32.maxvalue is the maximum value that string. length can achieve in theory.
2. In. Net, a single object occupies no more than 2 GB of memory, and each character of the Unicode-encoded string type occupies 2 bytes, so the maximum length is 1,073,741,823. In addition, this length cannot be met in 32-bit systems.
Some experts in the materials tested with a scientific and rigorous attitude of seeking truth from facts. After they ran to 1,000,000,000, they suffered a tragedy. Therefore, the conclusion was that they could exceed 1,000,000,000, but then the memory overflows. In fact, I also tested it, but I didn't see the maximum number of BITs, so the memory overflows...