Question Details

No question body available.

Tags

c#

Answers (8)

March 5, 2026 Score: 5 Rep: 37,321 Quality: Medium Completeness: 40%

See this possible [quite old] duplicate: What is the maximum possible length of a .NET string?.

The bottom line:
Yes, the theoretical limit is 2,147,483,647.
However - practically you might bump into a lower bound (e.g. max size of .NET object).


Another matter is that if that's really a concern for you, you probably have a design issue
(but you'll need to share a lot more details for a specific advice).

March 5, 2026 Score: 5 Rep: 16,516 Quality: Low Completeness: 0%

I would say that if that's a concern to you, we should rather speak about what you are trying to do and how to do it better.

March 5, 2026 Score: 2 Rep: 110,104 Quality: Low Completeness: 40%

Yes.

Remember each char is two octetes, so at 231-1 chars you are using 4GB of memory (which needs to be a single contiguous block).

There are options with other collections (which you can treat as ReadOnlySpan or ReadOnlySpan (encoding UTF-8) which give you access to many of the same operations).

Why do you want such long strings?

March 5, 2026 Score: 1 Rep: 31,065 Quality: Low Completeness: 30%

The length of the longest string I can create is 1073741791, which is Int.MaxValue / 2 - 32

March 5, 2026 Score: 0 Rep: 23,388 Quality: Low Completeness: 10%

misclicked on "thumb down" instead of "thumbs up", and got a message from stackoverflow "changing your vottee is not currently supported, but coming soon" :( sorry

March 5, 2026 Score: 0 Rep: 12,242 Quality: Low Completeness: 30%

For comparison: according to https://www.guinnessworldrecords.com/world-records/longest-novel, the longest book ever published has only about 10,000,000 characters, which is 0.5% of this limit.

March 5, 2026 Score: 0 Rep: 19 Quality: Low Completeness: 50%

Technically speaking, yes.

String.Length is an int, so the theorical max is Int.MaxValue = 2,147,483,647. To reach that limit you need to put a lot of information.

If this concern is made by curiosity, it's complicated fill the string. You can copy/paste the characters of a 300-page novel novel and you'll be OK. You can do it hundreds of time

if this is a real concern in your project — what are you actually trying to do? There's probably a better approach.

March 5, 2026 Score: 0 Rep: 8,710 Quality: Low Completeness: 30%

You could just quite easily try to create a string of that size: new string('x', int.MaxValue).