1
byte[][] s1_byte
static byte[][] ToBytes(string[] ascii)
{
    byte[][] results = ascii.AsEnumerable().Select(x => Encoding.UTF8.GetBytes(x)).ToArray();
    return results;
}

I want to convert this.

how to convert two dimensional byte array into a single dimensional byte array

1
  • 2
    Wording is pretty vague, how are you looking to combine them? Row by row? Column by column? Commented Jun 9, 2015 at 2:01

1 Answer 1

3

quick change would be using SelectMany

static byte[] ToBytes(string[] ascii)
{
    // use `SelectMany`
    byte[] results = ascii.AsEnumerable().SelectMany(x => Encoding.UTF8.GetBytes(x)).ToArray();
    return results;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Remove the AsEnumerable and you get cleaner code. It's not needed there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.