This article mainly introduces the method of converting char character arrays and strings in C#, and briefly analyzes the specific implementation skills of C# character arrays to strings and strings to character arrays in the form of examples. Friends who need it can refer to it. Next
The example of this article describes the method of converting char character array and string in C#. Share it with everyone for your reference, the details are as follows:
1. Convert string to character array
char[] tempChar = sourceString.ToCharArray();
2. Convert the character array to a string
//方法一 string str = string.Join("", tempChar); //方法二 string str = string.Concat<char>(tempChar); //方法三 string str = new string(tempChar);
Note: Method 1 uses a clever way because the original purpose of Join It is to concatenate the members in the collection and use the specified delimiter between each member. Here, the delimiter is specified as an empty string, so that the output effect is converted from a character array to a string. Method 2. The Concat method is used to concatenate the members of the enumerable interface implementation in the collection, and it can be used here. Method three uses the construction method of the string class, which is recommended.
The above is the detailed content of Detailed explanation of the method of converting char character array and string in C#. For more information, please follow other related articles on the PHP Chinese website!