Reputation: 7777
How can I set a value to a byte[]
I have tried the following but I get a compilation error:
byte[] XMLbyte=null;
XMLbyte = byte(2345)
Any suggestions how I can do this?
Upvotes: 0
Views: 26414
Reputation: 310
Try this: byte[] temp = new byte [255];
Or this: byte[] temp = new byte [123];
Upvotes: 0
Reputation: 3967
Some options to initialize an array:
XMLbyte = new byte[50]; // creates an array with 50 elements, all values are zero.
XMLbyte = new byte[3] {1,2,3}; // creates an array with 3 elements: 1,2,3
XMLbyte = new byte[] {1,2,3}; // creates an array with 3 elements: 1,2,3
XMLbyte = {1,2,3}; // creates an array with 3 elements: 1,2,3
Upvotes: 1
Reputation: 2205
You must XMLbyte = new byte[2345];
maybe you want a bytearray from "2345" string ?
System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
XMLbyte = encoding.GetBytes("2345");
Upvotes: 4
Reputation: 17556
try below code
byte[] XMLbyte=null;
XMLbyte = new byte[2] {1,2}
Upvotes: 0
Reputation: 1038850
You are looking for the GetBytes method:
byte[] XMLbyte = BitConverter.GetBytes(2345);
Upvotes: 0
Reputation: 1599
Well, it seems silly but I think you are missing the new operator
XMLbyte = new byte[2345]
Upvotes: 0