>Suppose I have an employee class
>
>
>public class Employee()
>{
> string sName = "";
>}
>
>
>I now want to create a collection of employee objects and pass it as a param to a method in another class.
>How do I do this?
>
>
>I will also want to return that collection from a method. Pseudocode:
>
>List
EmpCollection = SomeClass.GetEmpCollection();
>
>I'm not sure how to code this.
There are a number of ways to do this: Off the top of my head:
List list = SomeClass.GetEmpCollection();
In you employee class:
select name into data table(sqlreader) etc.. using sql client then :
Employee emp;
List myReturnList;
foreach (DataRow dr in myTable.Rows)
{
//
//error checking here
//
myReturnList.Add(new Employee(sName=dr["Name"].ToString())); (note this is 3.5 syntax using intializers)
}
return myReturnList
Hope this helps...