The maximum length of string in C #

Source: Internet
Author: User

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.