Click here to Skip to main content
15,920,688 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there any limitation for the size of a string in C #. Please let me know on this.
Thanks In advance.
Posted

Oh come on. If the length of the string is returned an int, don't you think it would be the maximum size of a 32-bit int?

2147483647 bytes
 
Share this answer
 
v2
Comments
Yusuf 9-Aug-10 14:50pm    
I hope he is not going to allocate that big of string...
Daniel Grunwald 9-Aug-10 16:45pm    
The Length property restricts the size to 2147483647 characters. .NET strings are stored as Unicode (UTF-16), so the maximum size is about 4 GB.
Of course, there may be other restrictions in the .NET runtime that prevent objects from being more than 2 GB (I think even the 64-bit .NET runtime has this restriction), so the actual limit may be a lot lower than that.
In my experience, anything larger than 200M characters and you're very likely to run into OutOfMemoryExceptions.
4 GB would be the maximum size of a string variable.
Until now, a few people found it lot less than that. So I have to try myself character by character to determine the exact size.

http://www.pcreview.co.uk/forums/thread-2539908.php[^]

:thumbsup:
 
Share this answer
 
What on earth would possess someone to ask this, instead of writing code to find out ?
 
Share this answer
 
Comments
Lima3 9-Aug-10 18:39pm    
hehehe !!!!!
Richard MacCutchan 10-Aug-10 6:35am    
I have a feeling you really know the answer to this question. :grin:
How big is your hard drive?
How big is your RAM?
How big is your imagination?
 
Share this answer
 
string does not have any predefine size.
 
Share this answer
 
v2
Comments
OriginalGriff 9-Aug-10 15:45pm    
Reason for my vote of 1
Yes it does: see JSOP's reply re the Length property. In practice you will hit other problems such as memory issues before loading up a string that long. Roughly the max string could be 2 gig, but the real issue is getting enough memory from the heap as an allocation, which would limit one to half that size.
Toli Cuturicu 10-Aug-10 10:29am    
Reason for my vote of 1
false

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900