Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass A Collection Of Objects As A Param
Message
From
15/08/2008 21:42:28
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01339253
Message ID:
01339258
Views:
8
>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...
Previous
Reply
Map
View

Click here to load this message in the networking platform