Summary of the differences between Ilist and list in C

  • 2020-06-07 05:11:06
  • OfStack

Frequently asked Questions:

Ilist < > It is only a generic interface, and since it is an interface, it cannot be instantiated
IList < Class1 > IList11 =new List < Class1 > ();
But why use it that way, why not just use List:
List < Class1 > List11 =new List < Class1 > ();

What are the benefits of the first usage?

To sum up:

Ilist < > It is supported in.es37EN2.0

Benefits:.. For example human and tiger have the function of the walk, you can put these classified into interface, when you have an animal class consists of the two kinds of animals, you want them to walk you only need one and the same method regardless of each other is what type, specific to walk, has two legs, but there are four limbs, the animal has four legs, this is the animal to the concrete to implement, but they are all four limbs swing when walking, and both forward 1 set distance (walking forward, of course), so I think that these can be classified as a behavior abstract, concrete step 1 can take depending on how far each Specific height/body length achieved.

Using IList < Class1 > IList11 =new List < Class1 > ();
Easy to modify later, when you are not using List to use other types
I just need to change this one place
Don't make too many changes

IList < > It's an interface that defines a set of operation methods that you have to implement

List < > IList is implemented as a type < > The methods defined

List < Class1 > List11 =new List < Class1 > ();
Is to create an List < Class1 > And you need to use List < T > Function to carry out relevant operations.
while
IList < Class1 > IList11 =new List < Class1 > ();

You just want to create 1 interface based IList < Class1 > Object instance, except that this interface is provided by List < T > The implementation. So it just wants to use IList < T > The function specified by the interface.

Interface for loose coupling... Conducive to the maintenance and reconstruction of the system... Optimize system flow...


Encourage the use of interfaces
This separates the functionality from the implementation
Implement the principle of interface separation
Not to see the actual need to use!


Related articles: