string length

Hi, I have a string which has the length 180857866. Is that okay for c# or vb.net?(Framework 4.0)
zhshqzycAsked:
Who is Participating?
 
DhaestCommented:
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.
http://msdn.microsoft.com/en-us/library/2839d5h5(v=VS.100).aspx
0
 
jdavistxCommented:
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?
0
 
mayank_joshiCommented:
System.String is a class in .net framework. It doesnt matter whether its vb or c#.both are complied into
MSIL.
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>Instead of doing += use a stringbuilder.

Notice that the StringBuilder has the same Int32.MaxValue limitation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.