在本文中,我们将讨论如何将字符数组转换为C#中的字符串。
在以下示例中,字符数组将转换为字符串。
这里声明字符数组并分配值,然后使用String s = new字符串(ch)语句转换为字符串。
C# 将字符数组转换为字符串示例
在下面的示例中,字符数组被转换为字符串。 首先声明了字符数组并为其赋值,然后使用 string s=new string (ch) 语句将其转换为字符串。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { char[] ch = new char[15]; ch[0] = 'O'; ch[1] = 'n'; ch[2] = 'i'; ch[3] = 't'; ch[4] = 'r'; ch[5] = 'o'; ch[6] = 'a'; ch[7] = 'd'; ch[8] = ' '; ch[9] = 'd'; ch[10] = 'o'; ch[11] = 't'; ch[12] = 'c'; ch[13] = 'o'; ch[14] = 'm'; string s = new string(ch); Console.WriteLine(s); Console.ReadLine(); } } }
日期:2020-04-11 22:50:19 来源:oir作者:oir