Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I want to collect all the display resolution details in variable.


CSS
HI,
Yes I want to create a array of structures, to store multiple value of below details.
  public struct slotInfo
        {
            public int HzRes;
            public int VtRes;
            public int RR;
            public int Bpp;
        }



How do i create array of structure
thanks,
shree
Posted
Updated 3-Jun-12 3:02am
v3
Comments
Sergey Alexandrovich Kryukov 3-Jun-12 1:40am    
Not clear? What is "structure array"? It is array of structures instances? Why array? What's the goal of the application? "10 resolution"? What do you mean? 10 what? How this is related to the question?
--SA
sri.v@rediffmail.com 3-Jun-12 9:00am    
HI,
Yes I want to create a array of structures, to store multiple value of below details.
public struct slotInfo
{
public int HzRes;
public int VtRes;
public int RR;
public int Bpp;
}

1 solution

The Array of slotInfo can be created as follows:
C#
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,
XML
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:
C#
var slotInfoArray = slotInfos2.ToArray();
 
Share this answer
 
v3
Comments
taha bahraminezhad Jooneghani 3-Jun-12 12:43pm    
5!
VJ Reddy 3-Jun-12 13:24pm    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900