Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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}


regards
Harish Reddy
Posted
Updated 21-Nov-11 0:44am
v2

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

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

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());
 
Share this answer
 
Try this, for small array

var c = a.Concat(b).ToArray();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900