can anyone tell me how to create a list in one class and access it from another?
See Question&Answers more detail:oscan anyone tell me how to create a list in one class and access it from another?
See Question&Answers more detail:ospublic class MyClass {
private List<string> myList = new List<string>();
public List<string> GetList()
{
return myList;
}
}
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 return myList
.
public class CallingClass {
MyClass myClass = new MyClass();
public void GetList()
{
List<string> calledList = myClass.GetList();
///More code here...
}
}