Microsoft introduce a new syntax in C#6 that let you set your property to read-only as below:
public class Animal
{
public string MostDangerous { get; } = "Mosquito";
}
I am wondering what is the added value of such approach.
What is the difference by just writing:
public class Animal
{
public const string MostDangerous = "Mosquito";
}
or even:
public class Animal
{
public string MostDangerous
{
get
{
return "Mosquito";
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…