i used IList with my day to day linq quaries but curious to know in simple words what is the diffrence between them i mean List and IList ?
Loading
i used IList with my day to day linq quaries but curious to know in simple words what is the diffrence between them i mean List and IList ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 27, 2024, 2:43 AM EST
Hi Abhishek Yadav,
ListandIListare related but have distinct differences.Listis a class that implementsIList, which is an interface.Listprovides more functionality and is mutable, allowing you to add, remove, and modify elements. On the other hand,IListis an interface that defines properties and methods for collections.Where to Use:
Listwhen you need a dynamic array that can grow or shrink in size.IListwhen you want to work with collections in a more generic way without specifying a particular implementation.Real-Life Example:
Imagine you have a shopping cart. You would use a
Listto store the items because you need to add, remove, or update items dynamically. However, if you have a method that accepts any collection type, you would useIListas a parameter type.In summary,
Listis mutable and provides more features, whileIListis more generic and allows flexibility in working with different collection types.Abhishek YadavRank #217 · 11.3K reputationPosted Feb 27, 2024, 2:45 AM EST
Jayraj Chhaya beautifull explantion brother
Sam HobbsRank #107 · 20.5K reputationPosted Feb 27, 2024, 12:20 PM EST
It is easy to understand the difference when we understand what interfaces are. An interface has methods defined but no implementation for the methods. It is not possible to declare (allocate using the
newoperator) an interface. Use of an interface requires defining a class that inherits the interface and that implements the methods. Or an interface can be used to specify that any such class can be used.Note that there are the following in the
System.Collections.Genericnamespace.IList Interface
https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ilist-1?view=net-8.0
List Class
https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=net-8.0
And the following in the
System.Collectionsnamespace.IList Interface
https://learn.microsoft.com/en-us/dotnet/api/system.collections.ilist?view=net-8.0
ArrayList Class
https://learn.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-8.0