Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pass A Collection Of Objects As A Param
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01339253
Message ID:
01339322
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.

You can create the list using code like:
List<Employee> employees = new List<Employee>();
employees.Add(new Employee());
To return it from a method, just specify the list of Employee as the return type:
public List<Employee> GetEmpCollection()
{
   return new List<Employee>();
}
Actually, I think it's suggested to use Collection<> for public types (List<> for internal collections) since it lets you receive notifications if the collection has changed (where List doesn't). So change that to:
public Collection<Employee> GetEmpCollection()
{
   return new Collection<Employee>();
}

Collection<Employee> employees = someClassInstance.GetEmpCollection();
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform