The
Array
of
slotInfo
can be created as follows:
slotInfo[] slotInfos = new slotInfo[10];
slotInfos[0] = new slotInfo() { HzRes = 1, VtRes=2, RR = 3, Bpp=4};
slotInfos[1]=new slotInfo() { HzRes = 5, VtRes=6, RR = 7, Bpp=8};
But, I think it is preferable to use
generic List<T>
as shown below,
List<slotInfo> slotInfos2 = new List<slotInfo>();
slotInfos2.Add(new slotInfo() { HzRes = 1, VtRes=2, RR = 3, Bpp=4});
slotInfos2.Add(new slotInfo() { HzRes = 5, VtRes=6, RR = 7, Bpp=8});
since it accommodates the items without pre defining the size. So, the List can grow according to the requirement.
Whereas in case of the array if the number of elements exceed the size of the array declared, then a new array with new size has to be created and the old elements have to be transferred to the new array as explained here
http://msdn.microsoft.com/en-us/library/bb348051(v=vs.90).aspx[
^]
However, if an
array
is specifically required then it can be obtained from the
List<T>
using the
ToArray
method as shown below:
var slotInfoArray = slotInfos2.ToArray();