c# - Clarification on why IList<T> doesn't inherit from IList -


the question why ilist<t> doesn't inherit ilist asked before , answered.

the correct answer believe if ilist<t> did inherit ilist, 1 cast ilist , add items not of correct type.

here comes question.

why list<t> implement both ilist<t> , ilist then? if cast list<t> ilist , add items not of type t correctly exception.

so what's purpose of list<t> implementing ilist?

then 1 cast ilist , add items not of correct type.

this partial justification: possible implement ilist in way no items of incorrect type can added - evidenced implementation list<t>.

however,, list<t> exists part of base class library. our convenience, implements ilist , throws exceptions. if want use ilist implementation, can within these constraints, , if not want use it, have no further work.

in contrast this, ilist<t> interface. if inherited ilist, every implementor of ilist<t> have implement of weakly-typed methods of ilist, adding lot of work not desired.

moreover, note list<t> implements ilist expilcitly. means, public interface of list<t> not grow; ilist methods if explicitly cast ilist. in interface, not possible, interface cannot enforce explicit implementation of interface.


Comments