Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi everyone.

The question is above.
I have a char array(let's say with length of 1000).
I want to assign it to a string(not a string array).

How can I achieve it?

My best regards...
Posted
Comments
Sergey Alexandrovich Kryukov 20-Nov-11 18:23pm    
For answering such question, better read MSDN.
--SA

You can use this constructor[^] of the String Class[^].
C#
string s = new string(myCharArray);
 
Share this answer
 
Comments
Un_NaMeD 20-Nov-11 17:15pm    
Thank you sir.
Sander Rossel 20-Nov-11 17:28pm    
No problem, glad to be of help :)
Sergey Alexandrovich Kryukov 20-Nov-11 18:22pm    
Correct, a 5; OP is advised to RTFM.
--SA
Sander Rossel 20-Nov-11 18:38pm    
Thanks! :)
Hi,

You can simply pass it into the string constructor
C#
char[] arr = new char[] {'a','b','c'};
string s = new string(arr);

Though it's not exactly an assignment, which would be impossible because of type safety.

Cheers, Boris
 
Share this answer
 
Comments
Un_NaMeD 20-Nov-11 17:16pm    
Thank you.
My 5!
Sergey Alexandrovich Kryukov 20-Nov-11 18:22pm    
Correct, a 5; OP is advised to RTFM.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900