can anyone tell me how to create a list in one class and access it from another?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
In case you need a List declared as static property
You can have any anything there instead of string. Now you can make an object of
MyClass
and can access the public method where you have implemented to returnmyList
.To create a list call the list constructor:
To make it accessible to other classes add a public property which exposes it.
To access the list from another class you need to have a reference to an object of type
Foo
. Assuming that you have such a reference and it is calledfoo
then you can writefoo.MyList
to access the list.You might want to be careful about exposing Lists directly. If you only need to allow read only access consider exposing a
ReadOnlyCollection
instead.