Thanks, and one more question

  • Thread starter Thread starter Carlo Razzeto
  • Start date Start date
C

Carlo Razzeto

First of all, thanks to Sherif ElMetainy and Jonathan Ruckert for answering
my last question. Now I have a real newbie question... Here is the scenario,
I am writing an object in C# called Account (represents the checking
account). This object will contain an array of Activity object (represents
account activity) which in turn will contain an array of Line_Item objects
(representing individual items associated with say, a Debit CC purchase.) In
my Account class, I have defined:

public Activity[] account_activity;

Later in my code (in a load_class() method) I want to fill in this array
with the appropriate number of activity objects (one for every row in my
Activity Table associated with the checking account). I am assuming that at
some point I need to define how big my array of Activity objects is going to
be (similar to the C++ int *i = new int[num];), how can this be done in C#?
Or does this need to be done in C#? I'm assuming that since .Net is fairly
strongly typed something like this would need to be done. Because of this I
was going through the trouble of declaring DataAdapters, DataTables and
DataSets so I can find out how many rows were returned from my query. Thanks
for any help,

Carlo
 
You should be able to do the following

public Activity[] m_objActivity = new Activity[10]; // number of array elements you need here

Regards
Jonathan Rucker
 
Once I've done this I can then properly instantiate each object with:

int i = 0;
foreach(DataRow Row in Table.Rows)
{
this.account_activity = new Activity(Row["item_id"].ToString());
i++;
}
???

See, what I have looks like:
class Checking_Account
{
public string account_id;
/* more variables */
public Activity[] account_activity;

private SqlConnection SQLConnection;
/* all other sql objects follow */

public Checking_Account(string account_id)
{
/* initialize sql objects */
try
{
load_class(account_id);
}
catch(Exception ex)
{
/* do approriate stuff */
}
}
private void load_class(account_id)
{
/* Init all non object variable representing Account table */
this.account_activity = new Activity[rows];
int i = 0;
foreach(DataRow Row in Table.Rows)
{
this.account_activity = new
Activity(Row["item_id"].ToString());
i++;
}
}
}
 
You may wish also to use the the IList class

e.g.

ArrayList m_objList = new ArrayList()
foreach(DataRow Row in Table.Rows

this.m_objList.Add(new Activity(Row["item_id"].ToString())


then when you wish to loop through etc.

foreach(Activity m_ActivityInfo in m_objList

// Do stuff here


Just a thought

Cheers
Jonathan Rucker
 
Back
Top