卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16333本站已运行3317

C#程序将字符列表转换为字符串

C#程序将字符列表转换为字符串

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);

Example

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);
      }
   }
}

Output

Converted to string = Hello

卓越飞翔博客
上一篇: C++语法错误:类型名需要用typename关键字标识,应该怎么处理?
下一篇: 如何处理C++开发中的编码转换问题
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏