In C#, the conversion between strings and character arrays can be realized by converting between string
and .char[]
Convert string
to char[]
:
string str = "hello";
char[] charArray = str.ToCharArray();
Convert char[]
to string
:
char[] charArray = new char[] {'h', 'e', 'l', 'l', 'o'};
string str = new string(charArray);
It should be noted that during the conversion process, new objects will be created and new memory will be allocated, so these conversion operations need to be used with caution when dealing with large amounts of data.