Click here to Skip to main content
12,747,366 members (37,563 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
HI, say I have an array

byte[] a = File.ReadAllBytes("a.doc");
byte[] b = File.ReadAllBytes("b.doc"); 

how to combine these 2 array into one array in such a way that both array should be there on new array?
Posted 16-Jan-13 4:42am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use a list and add each array using AddRange then convert back to an array
List<byte> list = new List<byte>();

byte[] c= list.ToArray();
Faisalabadians 16-Jan-13 9:52am
I am talking about byte[] not byte
CHill60 16-Jan-13 10:14am
That was my understanding of your question ...that's why the solution posted produces a byte[]
Marcus Kramer 16-Jan-13 10:38am
My 5. Absolutely correct.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi Faisalabadians.

about the solution of CHill60 - nice & simple (you got my 5+)

If performance is important and if you can use an IEnumerable<byte>, definitely prefer Linq's Concat<> method.

IEnumerable<byte> Con_A_and_B = a.Concat(b);

Andreas Gieriet 20-Jan-13 10:39am
My 5! That's also like I would do it (I would even use var, but that is debatable for many here... ;-)).
CHill60 21-Jan-13 4:13am
You're getting my +5 for this as well - about time I did more with Linq. Oh the joy of working with legacy versions of tools ;-p
Edo Tzumer 21-Jan-13 4:16am
tnx Andreas :)
Edo Tzumer 21-Jan-13 4:16am
Thank you Chill ;)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100