C
C#Newbie
Hi everyone, I'm new in this group and I have a question that might
have been answered already. I created an arraylist that I want to
contain the object that I created. But when I try to store these
objects, I end up having the same information in the arraylist. Here is
my code
in Person.cs
class PersonClass
{
string Name;
string Phone;
public PersonClass()
{
}
public PersonClass(string name, string phone)
{
Name = name;
Phone = phone;
}
}
in Call.cs
using Person;
class CallClass
{
ArrayList al = new ArrayList();
public CallClass()
{
DataSet personDataSet = new DataSet();
personDataSet = getAllPersons(); // function call to another
dll that I created
foreach(DataRow row in personDataSet.Tables[0].Rows)
{
al.add(new PersonClass(row[0].ToString(),
row[1].ToString());
}
}
}
So when I ran this program, my arraylist has the same information. What
is happening is that the new information is overwritting the object
previously stored. Any help would be appreciated. Thanks
have been answered already. I created an arraylist that I want to
contain the object that I created. But when I try to store these
objects, I end up having the same information in the arraylist. Here is
my code
in Person.cs
class PersonClass
{
string Name;
string Phone;
public PersonClass()
{
}
public PersonClass(string name, string phone)
{
Name = name;
Phone = phone;
}
}
in Call.cs
using Person;
class CallClass
{
ArrayList al = new ArrayList();
public CallClass()
{
DataSet personDataSet = new DataSet();
personDataSet = getAllPersons(); // function call to another
dll that I created
foreach(DataRow row in personDataSet.Tables[0].Rows)
{
al.add(new PersonClass(row[0].ToString(),
row[1].ToString());
}
}
}
So when I ran this program, my arraylist has the same information. What
is happening is that the new information is overwritting the object
previously stored. Any help would be appreciated. Thanks