5
In the line below:
public class Tree<TItem> where TItem : IComparable<TItem>
This line I’m creating the definition of type TItem
where TItem
implements the interface IComparable
, i.e., I am creating a generic type definition that implements what has been defined in the interface IComparable
as a method and/or properties.
My doubt would be on the line below, where the guy T
implements a class
. Why a class
and not a specific class? What is the purpose of creating a definition for the type T
that implements a class
?
public class Repository<T> : IDisposable where T : class
You can do
public class Repository<T> : IDisposable where T : classeExpecifica
but this makes itT
is no longer generic.– ramaral
@true ramaral still would be generic, because it would allow any type that is descending from the specified class and not only the class.
– Maniero
Thanks @ramaral, helped a lot!
– Kelly Soares
@Thanks for the correction.
– ramaral