List
for (int i=0; i<10; i++)
{
list.Add(i);
}
This works.
Now actually i want different types of data to be included
I want to include empno integer,empname string, dateofjoining date, salary double all these in a generic arraylist.
How should I do that, i.e. passing different datatypes in a single generic arraylist.
Kindly help
ClemPosted May 14, 2009, 9:26 PM
Try using the object type as the template of list object in order for the list object to accept/add different kinds/data-types of value, either value or reference types. Since, object class is the base class of all classes but remember that using this object class consumes more memory.
The code below might help.
List
Rupert BrucePosted May 7, 2009, 11:07 AM
Something like this:
class Employee
{
public int id;
public string name;
public double salary;
}
ArrayList myList = new ArrayList();
Employee fred;
fred.id=1;
fred.name="Fred Farquad";
fred.salary=123.45;
myList.Add(fred);
This is obviously missing a lot of detail and throws encapsulation out of the window...
StefanPosted Apr 18, 2009, 10:40 AM