samedi 1 juin 2019

Is it possible to define a recursive data structure using an interface?

Obviously it can be done with a class

public class MyClass
{
    public IEnumerable<MyClass> Children { get; set; }
}

but I'm not sure whether it can with an interface because I don't know of a way to refer to "the same type" within an interface.

Example:

public interface IMyClass
{
    public IEnumerable<IMyClass> Children { get; set; }
}

I thought maybe typed parameters could make this happen, but haven't been able to imagine a way.

Aucun commentaire:

Enregistrer un commentaire