首先,声明字符数组并设置每个字符的值 −
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#程序将字符列表转换为字符串的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2431685.html