The different between Strings and array of char.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

1. What is the different between String and Array of char ?
2. Should I use array of char if my string is longer than 200,000 chars and I need use IndexOf frequently ?
3. I'm sure that there isn't diferent between writing in C# or C++ since both of them using the same CLR / Framework,
am I wrong ?

With thanks,
Boba.
 
Boba said:
Hi,

1. What is the different between String and Array of char ?
2. Should I use array of char if my string is longer than 200,000
chars and I need use IndexOf frequently ?

Take a look at the StringBuilder class for that.

You could also try using unsafe code and locking an array of char so you can
use pointers to travel through it but i don't know if that will be much
faster that using StringBuilder.
3. I'm sure that there isn't diferent between writing in C# or C++
since both of them using the same CLR / Framework,
am I wrong ?

Depends if your C++ code is managed or not. You can still create C++ code
which doesn't depend on the clr/framework
With thanks,
Boba.

Yves
 
If we are talking about performance - StringBuilder is better than String since it's not immutable like the String
But still StringBuilder isn't so effiecient for searching and long Strings

Boba
 
You can use char c = mystring[20] if you like. A string is stored as a
char[], so not sure manually using a char[] is better. I guess it depends
on how you need to enum the chars and access stuff.

--
William Stacey, MVP

Boba said:
Hi,

1. What is the different between String and Array of char ?
2. Should I use array of char if my string is longer than 200,000
chars and I need use IndexOf frequently ?
3. I'm sure that there isn't diferent between writing in C# or C++
since both of them using the same CLR / Framework,
 
Back
Top