acadia
acadia

Reputation: 2621

Arraylist and list issue in C#

I have a arraylist of employees from the gridview in my ASP.net Page as shown below:

ArrayList tempempList = new ArrayList();
        List<Employee> emps = new List<Employee>();
        for (int i = 0; i < gvemp.Rows.Count; i++)
        {
            if (((CheckBox)gvemp.Rows[i].FindControl("cbAssign")).Checked)
            {
                tempempList.Add(((Label)gvemp.Rows[i].FindControl("lblempSeqNo")).Text);
            }
        }

Now I have List and Employee object consists of the following properties empID, empName,empAge,empSalary

Now for each empID from tempempList I need to populate the List

I am not sure how I can populate emps.

Appreciate your help

Upvotes: 1

Views: 138

Answers (1)

user596075
user596075

Reputation:

The List<T> object is just the strongly-typed version (generic) of ArrayList. ArrayList is preserved for traditional purposes, and List<T> should be utilized when necessary.

You can call the List<T>.Add() method, just like you did for the ArrayList.Add() method. So something like:

emps.Add(yourValue);

That should suffice.

Upvotes: 1

Related Questions