并列字符串列表 [英] Concatinating ths String lists

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

问题描述

朋友,

我是C#.net的新手.我需要合并两个String列表.我该怎么办?

Hi Friends,

I''m new to C#.net. I need to concat the two String lists. how can i do the following?

string[] a=  new string[fileA.Count] Ex: a, b, c, d
string[] b=  new string[fileB.Count] Ex: e, f, g, h



现在,我需要合并两个列表,例如



Now I need to Combine both the lists like

string[] c = new string[fileA.Length + fileB.Length]



我想要这样



i want like this

c[] = {a, b, c, d, e, f, g, h}



问候
Harish Reddy



regards
Harish Reddy

推荐答案

var newarray = new string[a.Length + b.Length];
a.CopyTo(newarray , 0);
b.CopyTo(newarray , a.length);


或在此处查看更多解决方案:
http://stackoverflow.com/questions/1547252/how-do- i-concatenate-two-arrays-in-c [ ^ ]


or see here for more solutions:
http://stackoverflow.com/questions/1547252/how-do-i-concatenate-two-arrays-in-c[^]


请尝试一下...

Please try this...

string[] a = new string[2];
            a[0] = "a";
            a[1] = "b";
            string[] b = new string[2];
            b[0] = "c";
            b[1] = "d";
            string[] c = new string[4];

            a.CopyTo(c, 0);
            b.CopyTo(c, a.Length);


            Console.WriteLine(c.ToString());


尝试此操作(适用于小型数组)

Try this, for small array

var c = a.Concat(b).ToArray();


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

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