Using Interface variables

后端 未结 12 1143
广开言路
广开言路 2020-11-28 05:01

I\'m still trying to get a better understanding of Interfaces. I know about what they are and how to implement them in classes.

What I don\'t understand is when you

12条回答
  •  一向
    一向 (楼主)
    2020-11-28 05:40

    Because this:

    public void ReadItemsList(List items);
    public void ReadItemsArray(string[] items);
    

    can become this:

    public void ReadItems(IEnumerable items);
    

    Edit

    Think of it like this:

    You have to be able to do this.

    rather than:

    You have to be this.

    Essentially this is a contract between the method and it's callers.

提交回复
热议问题