I'm trying to make a List<byte>
from a file that contains string (Hexadecimal) .
the definition is :
List<byte> myArray = new List<byte>();
if I want to add my information directly I use something like this :
myArray.Add(0xb8);
Note : Without any quotation or double-quotation .
The problem is when I want to do the same thing from file!
Now I want to know what 0xb8
's type is so I use the following code :
0xc3.GetType().ToString()
the result is : System.Int32 !!!!
but when I read strings from a file and use code like this , it give me the following error .
code :
Line = "0xb8";
myArray.Add(Convert.ToInt32(Line));
Error :
Argument 1: cannot convert from 'int' to 'byte'
and it's clear . because the only overload of myArray
gets only a byte
as argumant.
What makes thing so complicated for me is why it doesn't give me any error when I add a Int32
to myArray
in myArray.Add(0xb8);
.
I think it should be a form of byte ! maybe !
Why doesn't it give any errors and how can accomplish this scenario (I mean add byte from string to myArray ) ?