I have this simple code:
public static void Main(String[] args)
{
Data data = new Data { List = { "1", "2", "3", "4" } };
foreach (var str in data.List)
Console.WriteLine(str);
Console.ReadLine();
}
public class Data
{
private List<String> _List = new List<String>();
public List<String> List
{
get { return _List; }
}
public Data() { }
}
So when I'm creating a Data class:
Data data = new Data { List = { "1", "2", "3", "4" } };
The list was filled with strings "1", "2", "3", "4" even if it had no set
.
Why is this happening?