Read from Byte Array
-
The easiest way to read the data is to loop over the array. Here's a typical method for doing this:
for (int i = 0; i < myArray.Count; i++)
{
byte value = myArray[i];
}Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
Next time consider this: http://tinyurl.com/5vb53y9[^] However this is a good point where to start http://www.dotnetperls.com/byte-array[^] Take care
-
You can read larger base types from a byte array with BitConverter[^].
Be careful when using BitConverter. It uses the endianness of your CPU, so if you're byte array is coming from a hardware device with a different endianness, your BitConverter results will be messed up. See BitConverter.IsLittleEndian[^] Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
-
Be careful when using BitConverter. It uses the endianness of your CPU, so if you're byte array is coming from a hardware device with a different endianness, your BitConverter results will be messed up. See BitConverter.IsLittleEndian[^] Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
-
You can read larger base types from a byte array with BitConverter[^].
-
Actually i don't want its size. I need to get the value. When i iterating it displays the size. How can i get the value behind each array item?
Since your question mentioned a byte array, the size of each item is 1 byte. Pete O'Hanlon mentioned the item count within the array. One could call that a size, too.
DJ245 wrote:
When i iterating it displays the size.
What size exactly do you mean by this?
DJ245 wrote:
How can i get the value behind each array item?
Each item's value is exactly what Pete O'Hanlon's answer is concerning with.
Ciao, luker
-
Since your question mentioned a byte array, the size of each item is 1 byte. Pete O'Hanlon mentioned the item count within the array. One could call that a size, too.
DJ245 wrote:
When i iterating it displays the size.
What size exactly do you mean by this?
DJ245 wrote:
How can i get the value behind each array item?
Each item's value is exactly what Pete O'Hanlon's answer is concerning with.
Ciao, luker
Please check the screenshot http://doubts.posterous.com/bytearray-doubt[^] Actual value in the byteArray[0] is Name of an employee, [1] is code and son on... When iterating it returns only its size.. How can i get the Name of Employee from byteArray[0]?