I'm new to C# and I was trying to use set accessor to add a new Person object to a Person List called children in my class Person with the following approach, but also I want to use the get accessor to return an array of Persons.
the problem is that the value field in set accessor is an array of Person and I don't want it to be like that, I want it to be an Instance of Person NOT an array of persons, so I can add it to the List
class Person
{
private string firstName;
private string lastName;
public string FullName
{
get
{
return firstName + lastName;
}
}
public readonly DateTime dateOfBirth;
public readonly FavoriteColor favoriteColor;
private List<Person> children;
public Person[] Children
{
get
{
return children.ToArray();
}
set
{
children.Add(value);
}
}
}
So is there any thing that I can do to achieve that in C# using properties?