Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass A Collection Of Objects As A Param
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01339253
Message ID:
01339322
Views:
10
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform