Click here to Skip to main content
15,919,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all ,

I need to add array of bytes in c#.How can i do this?
Posted
Comments
Prerak Patel 1-Aug-11 3:26am    
Not clear. Elaborate more.
yeshgowda 1-Aug-11 3:28am    
I am getting some 50 bytes in each foreach loop i need to add those bytes from each loop and i need to compare the length of bytes

Do you really mean this?
C#
int sum = 0;
foreach (byte b in a)
  sum += b;
 
Share this answer
 
If I read between the lines correctly, you want to assemble a longer byte sequence from a number of arrays of bytes:
byte[][] myBytes = getMyBytes();
MemoryStream ms = new MemoryStream();
foreach (byte[] bytes in myBytes)   
    {
    ms.Write(bytes, 0, bytes.Length);
    }
byte[] results = ms.GetBuffer();
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900