An in depth analysis of the differences between IListless thanTgreater than and Listless thanTgreater than

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

When writing code, correct:
IList IList11 =new List ();
List List11 =new List ();

Some doubt, then search 1 on the net next, be inspired very much, collect then come down, but beg to differ to partial viewpoint, mark my opinion with red font!

First, the IList generic interface is a descendant of the ICollection generic interface and is the base interface for all generic lists.
It's just an interface for all generic types, and there aren't a lot of ways to use it, but if it's just a carrier for a collection of data, yes, IList can do it.
More often, however, we process the collection data to filter or sort it. At this point IList cannot help.

ILis when you only want to use methods of interfaces < > It saves space by not getting the other methods and fields of the class that implements the interface. (Since the subclass inherits from the parent class and has its own attributes and methods, the subclass NEW should have and must have these after it comes out, no matter in the parent class variable or in the variable of its own type, otherwise the data after the upward transformation and the downward transformation will be lost, too terrible!)

2, IList < > It's an interface that defines a set of operation methods that you have to implement for yourself, List < > Is a generic class that has implemented IList < > The methods defined

IList IList11 =new List ();
List List11 =new List ();

Both lines of code, operationally speaking, actually create an instance of an List object, that is, they operate without distinction.
It's just that the return value variable used to hold the operation is of a different type.
So, one way to think about it is that the purpose of these two lines of code is different.
List List11 =new List ();
Is to create 1 List, and need to use the List function, related operations.
IList IList11 =new List ();
You simply want to create an instance of an object based on the interface IList implemented by List. So it simply wants to use the functionality specified by the IList interface


Related articles: