Need Help in Arrays

I

Islam Elkhayat

here is my class
public class AppointmentRowCollection : Appointment
{
public Appointment[] GetRowsCollection(out int rows)
{
int i = 0;
dataset= new AppointmentDS();
dataset= SelectAppointment();
DataRowCollection drcollection = dataset.Appointments.Rows;
rows = drcollection.Count;
foreach (DataRow row in drcollection)
{
AppointmentID = int.Parse(row["AppointmentID"].ToString());
AppointmentDate= Convert.ToDateTime(row["AppointmentDate"]);
TimeFrom= row["TimeFrom"].ToString();
TimeTo= row["TimeTo"].ToString();
return new Appointment();
}
return null;
}
}

AppointmentID,AppAppointmentDate....... is a public property From
Appointment Class
How ca i return Appointment[] array form my foreach loop??
 
B

Brock Allen

foreach (DataRow row in drcollection)
{
AppointmentID = int.Parse(row["AppointmentID"].ToString());
AppointmentDate= Convert.ToDateTime(row["AppointmentDate"]);
TimeFrom= row["TimeFrom"].ToString();
TimeTo= row["TimeTo"].ToString();
return new Appointment();
}

How ca i return Appointment[] array form my foreach loop??

ArrayList al = new ArrayList();
foreach (....)
{
Appointment tmp = new Appointment();
al.Add(tmp);
}
return (Appointment[])al.ToArray(typeof(Appointment));
 
N

Nathan Neitzke

I am not going to go into this - but why do you have a collection inheriting
from the object it is a collection of? This is a poor design. Rather, it
should inherit from CollectionBase (if .NET <= v1.1) or (use generics .NET

Secondly, I would do the following -

Create an ArrayList and for each Appointment, just go ArrayList.add(new
Appointment() );

Then, return the ArrayList.ToArray() result.

Let me know if this works.

Take care.

--
Nathan

Or
Islam Elkhayat said:
here is my class
public class AppointmentRowCollection : Appointment
{
public Appointment[] GetRowsCollection(out int rows)
{
int i = 0;
dataset= new AppointmentDS();
dataset= SelectAppointment();
DataRowCollection drcollection = dataset.Appointments.Rows;
rows = drcollection.Count;
foreach (DataRow row in drcollection)
{
AppointmentID = int.Parse(row["AppointmentID"].ToString());
AppointmentDate= Convert.ToDateTime(row["AppointmentDate"]);
TimeFrom= row["TimeFrom"].ToString();
TimeTo= row["TimeTo"].ToString();
return new Appointment();
}
return null;
}
}

AppointmentID,AppAppointmentDate....... is a public property From
Appointment Class
How ca i return Appointment[] array form my foreach loop??
 
I

Islam Elkhayat

Thanx.. I'm new in C# so may be i miss some logic..
I'm using v1.1 what is CollectionBase??
I'm just try creat Data access Tier, but i don't have enought info about
this. would u help me to find good resource in how to develop my application
in 3 tier instead of but my code in the codebehind of my webform??

Nathan Neitzke said:
I am not going to go into this - but why do you have a collection
inheriting from the object it is a collection of? This is a poor design.
Rather, it should inherit from CollectionBase (if .NET <= v1.1) or (use
generics .NET

Secondly, I would do the following -

Create an ArrayList and for each Appointment, just go ArrayList.add(new
Appointment() );

Then, return the ArrayList.ToArray() result.

Let me know if this works.

Take care.

--
Nathan

Or
Islam Elkhayat said:
here is my class
public class AppointmentRowCollection : Appointment
{
public Appointment[] GetRowsCollection(out int rows)
{
int i = 0;
dataset= new AppointmentDS();
dataset= SelectAppointment();
DataRowCollection drcollection = dataset.Appointments.Rows;
rows = drcollection.Count;
foreach (DataRow row in drcollection)
{
AppointmentID = int.Parse(row["AppointmentID"].ToString());
AppointmentDate= Convert.ToDateTime(row["AppointmentDate"]);
TimeFrom= row["TimeFrom"].ToString();
TimeTo= row["TimeTo"].ToString();
return new Appointment();
}
return null;
}
}

AppointmentID,AppAppointmentDate....... is a public property From
Appointment Class
How ca i return Appointment[] array form my foreach loop??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top