I have some code where I\'m returning an array of objects.
Here\'s a simplified example:
string[] GetTheStuff() {
List s = null;
I know this is old question, but it's a basic question and I needed a detailed answer.
So I explored this and got results:
In .Net when you create an array (for this example I use int[]) you take 6 bytes before any memory is allocated for your data.
Consider this code [In a 32 bit application!]:
int[] myArray = new int[0];
int[] myArray2 = new int[1];
char[] myArray3 = new char[0];
And look at the memory:
myArray: a8 1a 8f 70 00 00 00 00 00 00 00 00
myArray2: a8 1a 8f 70 01 00 00 00 00 00 00 00 00 00 00 00
myArray3: 50 06 8f 70 00 00 00 00 00 00 00 00
int[] and char[] (a8 1a 8f 70 vs 50 06 8f 70)00 00 00 00 for myArray and 01 00 00 00 for myArray200 00 00 00). I don't know what its meaning.Now I feel a lot better about zero length array, I know how it works =]