The most obvious difference is that string is immutable. Therefore, you cannot change parts of it and create every new modification of a completely new copy.
The string itself has a very special implementation (this is a class of variable dimension) and is not supported by the array. I see no reason why access to read-only for char in a string should be slow.
So, if you want to change the small parts of a string, you need to use either StringBuilder or char[] . Of these two char[] there is / faster, since StringBuilder has additional checks and directions. But since this is an implementation detail, it may have changed since the last time I tested it.
Just compare it, and with .NET 4, setting the char[] member is about four times faster than StringBuilder . But both can perform more than 200 millionth tasks per second, so this rarely matters in practice.
Reading from char[] slightly faster (25% for my test code), which reads from string . Reading with StringBuilder on the other hand, is slower (3 times) than reading from char[] .
In all tests, I neglected the overhead of my other code. This means that my test underestimates the differences a bit.
My conclusion is that while char[] faster than alternatives, it only matters if you go through hundreds of megabytes per second.
//Write StringBuilder StringBuilder sb = new StringBuilder(); sb.Length = 256; for(int i=0; i<1000000000; i++) { int j = i&255; sb[j] = 'A'; } //Write char[] char[] cs = new char[256]; for(int i=0; i<1000000000; i++) { int j = i&255; cs[j] = 'A'; } // Read string string s = new String('A',256); int sum = 0; for(int i=0; i<1000000000; i++) { int j = i&255; sum += s[j]; } //Read char[] char[] s = new String('A',256).ToCharArray(); int sum = 0; for(int i=0; i<1000000000; i++) { int j = i&255; sum += s[j]; } //Read StringBuilder StringBuilder s= new StringBuilder(new String('A',256)); int sum = 0; for(int i=0; i<1000000000; i++) { int j = i&255; sum += s[j]; }
(Yes, I know that my control code is not very good, but I donβt think it matters much.)