Converting a char[] to a String

  • Thread starter Thread starter trellow422
  • Start date Start date
T

trellow422

How do I convert the following variable to a variable of
type String?

char[] record = new char[200];

I have tried the following:
String temp = record.ToString();
temp = System.Convert.ToString(record);

The result I get with both is "System.Char[]"

Any help would be greatly appreciated.

Thanks!
 
Here is one way:

char[] ca = new char[]{'0','1'};
string str = new string(ca, 0, 2);
Console.WriteLine("MyString from ca:"+str);
 
trellow422 said:
How do I convert the following variable to a variable of
type String?

char[] record = new char[200];

I have tried the following:
String temp = record.ToString();
temp = System.Convert.ToString(record);

The result I get with both is "System.Char[]"

Use the constructor for string which takes a char array:

string temp = new string(record);
 
You can create a new string based upon the char array:
string s = new string(record);

Maybe there are some other (better) solutions, but this one worked for me.
 
Back
Top