To use ilist or list? (Quiz)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.