List or Array?

If your going to be resizing your array as you add and remove items often using a list is best (resizing an array causes it to be copied).  If you need to be able to access array elements by index (rather than using for each) then use an array.  If you need both then you can use a list to create the final set of objects and then convert it to an array, or just use an array.

Create Arrays

	Byte[] MyArray;				//Declare a handle first
	MyArray = new Byte[3];		//Create the array

	//...do something

	MyArray = new Byte[3];		//If you want you can replace by creating a new array

or use this to declare it:

	Byte[] MyArray = new Byte[3];		//Declare and allocate space for the array

or this to set values at creation

	Byte[] MyArray = new Byte[3] {10, 4, 7 };

	int[] Values = {10, 27, 7, 12, 45};

Creating an array of constants in a function call

	SomeFunction(new byte[] { 0x00, 0x01 });

Convert array to string of values

	MyString = String.Join(",", MyArray);           //Output array as a string of values sperated with a comma
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *