zozo ahmed

zozo ahmed

  • NA
  • 18
  • 15.4k

create list of structure and add to list

Feb 20 2014 1:09 AM
I Write this code in c# , i declare array of structure but i do not know size of this array , I do not know how declare size for array of structure, i know about list and i try use it , but  i do not know how add to  list (xb,yb,size)with structure and how declare it?


public struct blocks
{

public Int32 xb;

public Int32 yb;

public Int32 size;
};
 namespace test
 {

class Program 


static static List<blocks> blocks1 = new List<blocks>();
 static void Main(string[] args)
{  
   
   Int32 index =0; 

  for (int y = 1; y < 5; y++)
   for (int x = 1; x < 5; x++) 
    {  
      blocks1[index].xb=x * 2; // store start point (x) of block  
      blocks1[index].yb = y *2; // store start point (y) of block  
      blocks1[index].size = 2; // store block size   index++; } } } } 

Answers (1)