I am very new to C# and I want to create an array of 200 records with each record structured as follows:
struct ChangeRec
{ public datetime TimeStamp;
public int Last ;
public int [] mode
}
The problem is how do I initialize the mode array to 20 records, and how do I access the array dynamically? I am not bound to use a struct etc, I just need the functionality of an array that has the mode array as part of its record structure.
Jan MontanoPosted Jan 9, 2009, 12:03 AM
ChangeRec[] changeRec = new ChangeRec[200];
for (int i=0; i
// initialize earch changeRec mode with 20 records with index 0 - 19
changeRec[i].mode = new int[20];
}
// access the 6th mode of the 51st changeRec
changeRec[50].mode[5] = 5;
Komal PatelPosted Jan 8, 2009, 11:56 PM
heare is ur structure
struct ChangeRec
{
public DateTime TimeStamp;
public int Last;
public int[] mode;
public ChangeRec(int no)
{
TimeStamp = DateTime.Now;
Last = 0;
mode = new int[no];
}
}
now use the folowing code to initiallize your structure object array
ChangeRec[] c = new ChangeRec[20];
for (int i = 0; i < c.Length;i++)
c[i] = new ChangeRec(20);
and here is the code to work with each object's array element
c[0].mode[0] = 2;
Response.Write(c[0].mode[0].ToString());
this works for this simple example hope it work for your requirements..