CraigBroadman
asked on
Array Of Structs
Hi
I have the below Struct
struct staff
{
public string fullName;
public string monthYear;
public int hits;
public staff(string fullName, string monthYear, int Hits)
{
this.fullName = fullName;
this.monthYear = monthYear;
this.hits = Hits;
}
}
And then I have a Stored Procedure that gets a list of hits for various employees, see example below
Jim, June, 50
Jim, May, 34
Jim, April, 26
Simon, June, 22
Simon, May, 20
Simon, April, 21
Sam, June, 44
Sam, May, 15
Sam, April, 19
What I then want to do is put this information into an array of structs, all I have got so far is.........
Obviously looping through the records and.......
staff staffDetail = new staff(reader["Employee"].T oString(), reader["HitMonth"].ToStrin g(), Convert.ToInt32(reader["Hi ts"].ToStr ing()));
staff[] staffList = { staffDetail };
But this is obviously wrong, i'm new to C# and new to Structs, any information very gratefully received.
Craig
I have the below Struct
struct staff
{
public string fullName;
public string monthYear;
public int hits;
public staff(string fullName, string monthYear, int Hits)
{
this.fullName = fullName;
this.monthYear = monthYear;
this.hits = Hits;
}
}
And then I have a Stored Procedure that gets a list of hits for various employees, see example below
Jim, June, 50
Jim, May, 34
Jim, April, 26
Simon, June, 22
Simon, May, 20
Simon, April, 21
Sam, June, 44
Sam, May, 15
Sam, April, 19
What I then want to do is put this information into an array of structs, all I have got so far is.........
Obviously looping through the records and.......
staff staffDetail = new staff(reader["Employee"].T
staff[] staffList = { staffDetail };
But this is obviously wrong, i'm new to C# and new to Structs, any information very gratefully received.
Craig
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have actually used an Array List now
Thanks all
Thanks all
staff[] staffList = new staffList[2];
then
staffList[0] = staffDetail ;
staffList[1] = staffDetail ;
you can also do
ArrayList al = new ArrayList();
al.Add( staffDetail );
but, pay attention since structs are passed by value in c#
hth,
A.