Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass A Collection Of Objects As A Param
Message
De
15/08/2008 21:42:28
John Baird
Coatesville, Pennsylvanie, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01339253
Message ID:
01339258
Vues:
11
>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...
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform