Peter Peter - 1 year ago 272
C# Question

How to convert IEnumerable to byte array

I need to combine several arrays to one. I've found that seems to be a good way to do this:

IEnumerable<byte> Combine(byte[] a1, byte[] a2, byte[] a3)
foreach (byte b in a1)
yield return b;
foreach (byte b in a2)
yield return b;
foreach (byte b in a3)
yield return b;

However, I'm not well familiar with
. How do I convert the result back to
so I could work further with it?

Thank you.

Answer Source

Instead of iterating them just linq's .Concat:

var joint = a1.Concat(a2).Concat(a3);

If you want to return it as an array:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download