C# creating class collection or arraylist of my class object

i have an information class that gets populated with some actions. I can have more than one action for a given user


[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Collections;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Collections.Generic;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Text;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MCO.BusinessEntities[/COLOR][/SIZE]
 
 

[SIZE=2]{[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][/INDENT][INDENT][SIZE=2]{[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] mActionID;[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] mActionDescription;[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#008000]//return [/COLOR][/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] ActionID[/SIZE][/INDENT][INDENT][SIZE=2]{[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][SIZE=2] { [/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] mActionID; }[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][SIZE=2] { mActionID = [/SIZE][SIZE=2][COLOR=#0000ff]value[/COLOR][/SIZE][SIZE=2]; }[/SIZE][/INDENT][SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] ActionDescription[/SIZE]
 
 

[SIZE=2]{[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][SIZE=2] { [/SIZE][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][SIZE=2] mActionDescription; }[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][SIZE=2] { mActionDescription = [/SIZE][SIZE=2][COLOR=#0000ff]value[/COLOR][/SIZE][SIZE=2]; }[/SIZE][/INDENT][SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#008000]//constructor[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2] BEPersonActions([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] actionID, [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] actionDescription)[/SIZE]
 
 

[SIZE=2]{[INDENT]mActionID = actionID;[/INDENT][/SIZE]

[INDENT][SIZE=2]mActionDescription = actionDescription;[/SIZE][/INDENT][SIZE=2]}[/SIZE]
 
 

[/INDENT][SIZE=2]}[/SIZE]
 
 

[/INDENT][SIZE=2]}[/SIZE]

i need to populate this class with values from the database and then later need to use on the page.

i have used arraylist for my testing and it is working but can’t i make my class object to be an arraylist? There should be a better way of doing this than what i am doing.

code to populate my test data from my data layer


[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Collections;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Collections.Generic;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Text;[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][SIZE=2][COLOR=#000000] MCO.DAL[/COLOR][/SIZE]
 
 

[SIZE=2]{[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]class [/COLOR][/SIZE][SIZE=2][COLOR=#008080]DALGetActions[/COLOR][/SIZE][/INDENT][INDENT][SIZE=2]{[/SIZE][/INDENT][INDENT][INDENT][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2][COLOR=#000000] ArrayList[/COLOR][/SIZE][SIZE=2][COLOR=#000000] GetAtions(myUser[/COLOR][/SIZE][SIZE=2][COLOR=#000000])[/COLOR][/SIZE][/COLOR][/SIZE][/INDENT]

[SIZE=2][COLOR=#008080][INDENT][SIZE=2]{[/SIZE][/INDENT][/COLOR]
 

[/SIZE][INDENT][INDENT][SIZE=2][COLOR=#008080]ArrayList[/COLOR][/SIZE][SIZE=2][COLOR=#000000] myActionList = [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#008080]ArrayList[/COLOR][/SIZE][SIZE=2][COLOR=#000000]();[/COLOR][/SIZE][/INDENT]

[INDENT][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2] myAction1 = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2](1, [/SIZE][SIZE=2][COLOR=#800000]"Action 1"[/COLOR][/SIZE][SIZE=2]);[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2] myAction2 = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2](2, [/SIZE][SIZE=2][COLOR=#800000]"Action 2"[/COLOR][/SIZE][SIZE=2]);[/SIZE][/INDENT][INDENT][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2] myAction3 = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2](3, [/SIZE][SIZE=2][COLOR=#800000]"Action 3"[/COLOR][/SIZE][SIZE=2]);[/SIZE][/INDENT][INDENT][SIZE=2]myActionList.Add(myAction1);[/SIZE][/INDENT][INDENT][SIZE=2]myActionList.Add(myAction2);[/SIZE][/INDENT][INDENT][SIZE=2]myActionList.Add(myAction3);[/SIZE][/INDENT]

[INDENT][SIZE=2]return myActionList;[/SIZE][/INDENT][SIZE=2]}[/SIZE]
 

[/INDENT][SIZE=2]}[/SIZE]
 

[/INDENT][SIZE=2]}[/SIZE]

test code on the page where i am using it


[SIZE=2][COLOR=#008080]ArrayList[/COLOR][/SIZE][SIZE=2][COLOR=#000000] PersonActions = [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2][COLOR=#008080]ArrayList[/COLOR][/SIZE][SIZE=2][COLOR=#000000]();[/COLOR][/SIZE]
[SIZE=2][COLOR=#000000]PersonActions = [COLOR=#008080]DALGetActions[/COLOR].GetActions(SignInUser);[/COLOR][/SIZE]
[SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2][COLOR=#000000] myAction1 = ([/COLOR][/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2][COLOR=#000000])PersonActions[0];[/COLOR][/SIZE]
[SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2] my[COLOR=#000000]Action[/COLOR]2 = ([/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2])PersonActions[1];[/SIZE]
[SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2] my[COLOR=#000000]Action[/COLOR]3 = ([/SIZE][SIZE=2][COLOR=#008080]BEPersonActions[/COLOR][/SIZE][SIZE=2])PersonActions[2];[/SIZE]
[SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] action1Description = my[COLOR=#000000]Action[/COLOR]1.ActionDescription;[/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] action1ID = my[COLOR=#000000]Action[/COLOR]1.ActionID;[/SIZE]

There are some better ways, but they revolve around using more suitable collections. If you are using 1.1 you are kind of SOL unless you can get a copy of codesmith and its very, very handy strongly typed collection generator. If you are using 2.0 you can use List<T> to give you all the benefits of a strongly typed array list without any fuss.

i am using 2.0. Can you please provide an example for List<t>?

Thanks

uh . . .

List<BEPersonAction> l=new List<BEPersonAction();
BEPersonAction action=GetAction();
l.Add(action);

They work just like arraylists. But they are strongly typed and oh so sweet.