首先,宣告字元陣列並設定每個字元的值−
char[] ch = new char[5]; ch[0] = 'H'; ch[1] = 'e'; ch[2] = 'l'; ch[3] = 'l'; ch[4] = 'o';
Now, use the string class constructor and create a new string from the above array of characters −
string myChar = new string(ch);
Let us see the code to convert a list of characters to string in C#.
Live Demo
using System; namespace Demo { class MyApplication { static void Main(string[] args) { char[] ch = new char[5]; ch[0] = 'H'; ch[1] = 'e'; ch[2] = 'l'; ch[3] = 'l'; ch[4] = 'o'; string myChar = new string(ch); Console.WriteLine("Converted to string = {0}", myChar); } } }
Converted to string = Hello
以上是C#程式將字元清單轉換為字串的詳細內容。更多資訊請關注PHP中文網其他相關文章!