I have the following Person
class
class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get { return FirstName + " " + LastName; }
}
public IEnumerable<Person> Children { get; set; }
}
I could initialize it like this:
Person p = new Person() { FirstName = "John", LastName = "Doe" };
But is it possible to reference another property of Person
in the object initializer, so I could do for example something like this?
Person p = new Person()
{
FirstName = "John",
LastName = "Doe",
Children = GetChildrenByFullName(FullName);
};
EDIT
For the sake of the question, the referenced property doesn't have to be calculated according to other properties, but its value could be set in the constructor.
Thanks
You can't do that: