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?
Your method doesn’t return a list of
byte– it returns a list ofbyte[], of byte arrays.Since your input is an array of byte arrays, you can probably simply convert from one to the other.
With LINQ:
Without LINQ: