字符转换为字符串 [英] Character conversion into string

查看:84
本文介绍了字符转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中将字符列表转换为字符串列表?

解决方案

从这里开始: http://msdn.microsoft.com/en-us/library/ttyxaek9.aspx [ ^ ]。



你列出的是方法 ToArray



案件是否结案?



-SA


您好,

您能否提供详细信息。你是什​​么意思的字符串列表(字符串是字符数组)。



如果你在谈论转换字符串中的字符数组



  char  [] charAray =  new  < span class =code-keyword> char  [] {'  h',< span class =code-string>'  e''  l''  l''  o'}; 
string mystring = new string (charAray);







如果你需要将char数组转换为字符串数组,那么你有许多解决方案,如迭代。

我建议你创建一个扩展方法,它可以将源解析为目标类型。

这里有更多细节,通用扩展方法供你参考



  public   static  扩展名
{
public 静态列表< t> ToList< t>( IEnumerable来源)其中 T: class
{
List< t> collection = new List< t>();

foreach var x in source)
{
T info = Convert.ChangeType(x, typeof (T)) as T;
collection.Add(info);
}

return 集合;
}
}


/// / ////////////////////////////////////////////////// ////////////

char [] charAray = new char [] {' h'' e' ' l'' l'' o'};
List< string> strList = charAray.ToList< string>();

< / string > < / string > < / t > < / t > < / t > < / t >


how to convert character list into string list in C#?

解决方案

Start from here: http://msdn.microsoft.com/en-us/library/ttyxaek9.aspx[^].

And you list has the method ToArray.

Is the case closed?

—SA


Hi,
Can you provide detail. What do you mean by string List (string is array of characters).

If you talking about to convert character array in string

char[] charAray = new char[] {'h','e','l','l','o' };
string mystring = new string(charAray);




If you need to convert char array into string array, then you have many solutions like iterations.
I recommend you to create an extension method, which can parse source into target type.
For more detail here is generic extension method for your reference

  public static class Extensions
    {
        public static List<t> ToList<t>(this IEnumerable source) where T : class
        {
            List<t> collection = new List<t>();

            foreach (var x in source)
            {
                T info = Convert.ChangeType(x, typeof(T)) as T;
                collection.Add(info);
            }

            return collection;
        }
    }


//////////////////////////////////////////////////////////////////

char[] charAray = new char[] {'h','e','l','l','o'};
List<string> strList = charAray.ToList<string>();

</string></string></t></t></t></t>


这篇关于字符转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆