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 });

2 Dimensional Arrays

	string[,] My2DimensionalArray;
	My2DimensionalArray = new string[0, 0];

Or as a jagged array

	string[][] My2DimensionalArray;
	My2DimensionalArray = new string[2][];
	My2DimensionalArray[0] = new string[20];
	My2DimensionalArray[1] = new string[20];

Convert array to string of values

	MyString = String.Join(",", MyArray);           //Output array as a string of values sperated with a comma
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.