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

2023年 8月 27日 46.4k 0

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#程序将字符列表转换为字符串的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论