To create a list, call the list constructor:
class Foo { private List<Item> myList = new List<Item>(); }
To make it available to other classes, add a public property that exposes it.
class Foo { private List<Item> myList = new List<Item(); public List<Item> MyList { get { return myList; } } }
To access a list from another class, you need to have a reference to an object of type Foo . Assuming you have such a link and it is called Foo , you can write foo.MyList to access the list.
You may be careful to display lists directly. If you only need to allow read-only access, consider ReadOnlyCollection instead.
Mark byers
source share