Glitch in Monodevelop for loops!!!

Predict the output before you read the bottom!

private InventorySlot[] FillInventoryWithJunk (int Cols, int Rows, int storageType, InventoryItem junk, int[] skipSlots)
	{
		InventorySlot[] itemsStorage = new InventorySlot[Rows * Cols];

		for(int i = 0; i < itemsStorage.Length; i++)
		{
			itemsStorage *= new InventorySlot(junk);*

_ itemsStorage*.Item.ID = i;_
_
}*_

_ for(int i = 0; i < Rows * Cols; i++)
* {*
Debug.Log(itemsStorage*.Item.ID);
}*_

* return itemsStorage;*
* }*
Should the output not be 0, 1, 2, 3, 4, 5? What is actually output is “5, 5, 5, 5, 5”.
If the ID’s were not changed it would output all 1’s as thats what the “Junk” item ID is.
If the debug.log is placed in the first loop it outputs correctly. If the ID assignment line is place in a separate loop, it still outputs not as expected in the debug loop.
Ive been stuck on this for days. Any help would be amazing. Thanks in advance.

You are setting the Item.ID on the same ‘junk’ object each time through. That’s why it says 5,5,5,5,5 instead of 0,1,2,3,4.

Try copying/cloning/instantiating the prefab/dummy ‘junk’ object each time you want to add it to the array instead of using the same reference for all array elements.