How to use the List Class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a little bit confused on the concept of using a List Class. Here is what
I want to be able to do:

1) I create an object called "NotePage"
2) I want to add several "NotePage" objects to a "NoteBook" List
3) I then want to be able to pass a List Class as a parameter to a method call

Can anyone give me some examples on how to do this or at least point me in
the right direction? I am about to go nuts here.

Thanks.
 
Noble,

It's pretty simple. You can do this:

// In your code:
List<NotePage> notebook = new List<NotePage>();

// Add your items.
notebook.Add(new NotePage());

And then pass notebook to your methods.
 
Noble said:
I am a little bit confused on the concept of using a List Class. Here is what
I want to be able to do:

1) I create an object called "NotePage"
2) I want to add several "NotePage" objects to a "NoteBook" List
3) I then want to be able to pass a List Class as a parameter to a method call

Can anyone give me some examples on how to do this or at least point me in
the right direction? I am about to go nuts here.

void SomeMethod(List<NotePage> pages)
{
// ...
}

void SomeOtherMethod()
{
List<NotePage> NoteBook = new List<NotePage>();
NotePage page = new NotePage();

NoteBook.Add(page);

SomeMethod(NoteBook);
}

Pete
 
You can also do this:


public class Employee
{}


public class EmployeeCollection : List <Employee>
{

}


This will give you instant strong typed collections.....a vast improvement
over 1.1 CollectionBase stuff.


You don't have to do this, you just ~can do this.



List <Employee> allEmployees = new List <Employee>();

works as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top