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

问题描述

朋友,

我是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[^]


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


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


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

08-20 23:20