Introduction to the method of converting char character array and string in C#

黄舟
Release: 2017-03-06 11:32:04
Original
1915 people have browsed it

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();
Copy after login

2. Convert the character array to a string

//方法一
string str = string.Join("", tempChar);
//方法二
string str = string.Concat<char>(tempChar);
//方法三
string str = new string(tempChar);
Copy after login

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 introduction of the method of converting char character array and string in C#. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template