Let's assume, we have following class:
public class foo
{
private string something
public string Something
{
get { return something; }
set { something = value; }
}
}
If we don't need to use field something, we can write it shortly, as:
public class foo
{
public string Something { get; set; }
}
It's OK.
But is there a way to short-write following class:?
public class foo
{
private List<string> something = new List<string>()
public List<string> Something
{
get { return something; }
set { something = value; }
}
}
EDIT:
OK, found How do you give a C# Auto-Property a default value?
And since c# 6 we can write:
public List<string> Something { get; set; } = new List<string>();
Thanks for attention.