I have classes, father and child (for example)
Fragment of my implementation
Class Father.cs
public class Father
{
public int Id { get; set; }
public string Name { get; set; }
public List<Child> Children { get; set; }
public Father()
{
}
}
Class child.cs
public class Child
{
public int Id { get; set; }
public string Name { get; set; }
public Child()
{
}
}
I'm trying to do something like this
Father f = new Father();
f.Children[0];
f.Children[1];
f.Children["John"];
I am now, its wrong, I need to implement something in the Child Class, I tried this
public Child this[string name]
{
get
{
return this;
}
}
But that does not work.
How can I implement this function for my Child class?
source
share