i have a variable with string type.for example string test;
.how many character i can set for test?thanks.
views:
76answers:
2
+8
A:
The maximum size of all reference type (like a string) instances is limited by the CLR to 2GB. Since a character in .NET takes 2 bytes, that means a string can hold a maximum of around 1 billion characters.
Note that .NET strings aren't really designed for these sizes. They are immutable and all string operations create new string instances. When you have data this large, you need to custom-design your algorithms and in-memory (and probably on-disk, for really huge data) structures around what you want to do with it.
dtb
2010-09-20 16:50:11
Can you further explain why a 2GB limit on the CLR equates to "1G characters"?
StriplingWarrior
2010-09-20 16:54:11
@StriplingWarrior: Keep in mind that each character takes 2 bytes in .NET.
dtb
2010-09-20 16:58:06
@dtb: i can't set 11 million character in string variable?is it true ok?
na.fa
2010-09-20 17:07:35
@dtb: Thank you for the edit. It is a much better answer now.
StriplingWarrior
2010-09-20 17:24:39