I have a list i am trying to pass from one class to another. Here is the code:
namespace Test
{
Class1
{
public IList<string> MyList { get; set; }
internal Class1()
{
MyList = new List<string>();
}
public void AddValues()
{
MyList.Add("123");
}
}
}
Class2
{
Class1 c = new Class1();
var a = c.MyList;
}
Everytime i run this i am getting 0 value in Class2 for MYList. What am i doing wrong?
My thinking is it is going to constructor again and initializing MyList again when it is called from Class2. But i cannot initialize MyList in method AddValues either as it is being called many times from another class. So i am confused how can i do this. Searched on google but did not find any answers.