string length

Hi, I have a string which has the length 180857866. Is that okay for c# or 4.0)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
The Length property returns an int, so the maximum length of a string is Int32.MaxValue (2,147,483,647) characters. Practically this will probably mean that you can make your string as long as you have memory available to put it in.

Your more likely to be hitting memory problems than string length problems. Instead of doing += use a stringbuilder.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Even if it's a 64-bit machine, you cannot create an object that is greater than 2GB in size within .NET.  I believe each character in a string is allocated 2 bytes; therefore, your string would consume about 344MB of space.

So, no, your string shouldn't be a problem.

Of course, there's always the question of why you're manipulating such large strings?
System.String is a class in .net framework. It doesnt matter whether its vb or c#.both are complied into
Éric MoreauSenior .Net ConsultantCommented:
>>Instead of doing += use a stringbuilder.

Notice that the StringBuilder has the same Int32.MaxValue limitation.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.