Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many character can set for string variable?

I have a variable with string type. For example string test;.

How many character i can set for test? Thanks.

like image 501
Farna Avatar asked Sep 20 '10 16:09

Farna


1 Answers

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.

like image 119
dtb Avatar answered Oct 07 '22 01:10

dtb