0

I am having a method which must return List of Bytes as follow:

 public List<byte[]> ExportXYZ(IPAddress ipAddress, WebCredential cred) 

Inside above method I am calling third party method which returns a multi-dimensional byte array:

 byte[][] tempBytes = xyzProxy.ExportCertificates(); 

So now I need to convert byte[][] to List<byte[]>.

I wrote below code

private List<byte[]> ConvertToSigleDimensional(byte[][] source) { List<byte[]> listBytes = null; for(int item=0;item < source.Length;item++) { listBytes.Add(source[i][0]); } return listBytes; } 

I feel this is not a good way of coding. Can anyone help me to write proper code for the conversion?

1 Answer 1

4

Your method doesn't return a list of byte - it returns a list of byte[], of byte arrays.

Since your input is an array of byte arrays, you can probably simply convert from one to the other.

With LINQ:

 byte[][] arr = ...; List<byte[]> list = arr.ToList(); 

Without LINQ:

 byte[][] arr = ...; List<byte[]> list = new List<byte[]>(arr); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.