How to implement an interface to a List object

379 views Asked by At

Ok, the question is really general. I have a generic interface:

public interface IGizmo<T>

and a class implementing the interface

public class A:IGizmo<A>

How can I implement the interface

IGizmo<List<A>>

on objects of the form:

List<A> L

Or if the above is not possible, is there a "natural way" to implement an interface to a list object class from an interface defined on the class?

1

There are 1 answers

2
PWT On

Your interface is a Generic interface, your implementation could be:

public class ObjectWithoutList : IGizmo<A>

public class ObjectWithList : IGizmo<List<A>>

Without more context I believe you've misunderstood generics? If not could you give more info?

Otherwise see these links for more info on Generics:

Pluralsight Course

Microsoft Docs