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

	// 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[2,3];
Jagged 2 Dimensional Arrays

	string[][] My2DimensionalArray;
	My2DimensionalArray = new string[2][];
	My2DimensionalArray[0] = new string[6];
	My2DimensionalArray[1] = new string[4];



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.


Your email address will not be published.