Код: Выделить всё
internal class Program
{
static void Main(string[] args)
{
Child child = new Child
{
Test = { Name = "hello" }
};
//child.Test.Name prints out "hello"
}
}
public class Child : Parent
{
public Child()
{
}
}
public abstract class Parent
{
public Test Test { get; }
protected Parent()
{
Test = new Test { Name = "Default" };
}
}
public class Test
{
public string Name { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... nitializer
Мобильная версия