An example of a common interface is IEnumerable<T> . It is a collection that you can list. The type of elements in the collection is not related to the interface, so it allows you to specify this using a common parameter.
You can, for example, create a class as follows:
class Foo<T, E> where T : IEnumerable<E> { }
Thus, the general parameter T can only be a collection of type E. The hiding interface is also common. You can also do this:
class Foo<T> where T : IEnumerable<string> { }
In this case, you do not allow any type of collection, but only a collection of strings. You can go crazy like this:
class Foo<T> where T : IEnumerable<T> { }
Where T should be some collection that contains T. collections
source share