Can’t i overload List’s Add method ?
class ListDemo<T>:List<T>
{
public override T Add<T>(T value)
{
return base.Add(value);
}
}
I am receiving the following error :
1) Type parameter ‘T’ has the same name as the type parameter from outer type ‘CollectionsExample.ListDemo
2) ‘CollectionsExample.ListDemo.Add(T)’: no suitable method found to override
Instead of subclassing from
List<T>, you should encapsulateList<T>and implementIList<T>. This makes it easy to handle “overriding” the behavior of Add:List<T>should not be part of your public API – it should be an implementation detail.