I have a class that has an internal list of other objects like so:
public class Parent
{
List<Child> _children;
}
where Child say looks like this:
public class Child
{
public string Name;
}
What I want to do is set up parent where the members of _children can be accessed like so:
...
Child kid = parentInstance["Billy"]; // would find a Child instance
// whose name value is Billy
...
Is this possible? I could obviously do something like this:
Child kid = parentInstance.GetChild("Billy");
But I prefer the array/dictionary like syntax. This isn’t a big deal if it isn’t, and I don’t want to have to jump through a million hoops for what amounts to syntactic sugar.
You could define an indexed property to the
Parentclass: