After reading my introduction to list, a friend thought that list <t> is very powerful, so he wanted to use it when he saw the set.
However, we have always advocated design to interface. According to this idea, we should try our best to use ilist in variable Declaration (declare) and method signature (Signature) <t>. as follows:
Class Demo
{
Private Ilist < Int > List = New List < Int > ;
Public Void Dosomething (ilist < T > L)
{
//L. foreach (); U can't do it.
}
}
So he asked me this question. Since it is declared as ilist <t>, how can I use some convenient functions (such as the foreach method) specific to list <t>? You cannot change the Declaration to list <t> for this purpose. In this case, it is not intended to use a specific object, which breaks the design to interface principle.
This question is very interesting. I'm afraid other friends may also have this question. What do you think should you do? What inspiration does this question give us?
Tip: the solution is simple, but the ideas are worth learning.