HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

List<T> or IList<T>

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
ilistliststackoverflow

Problem

Can anyone explain to me why I would want to use IList over List in C#?

Related question: Why is it considered bad to expose List

Solution

If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than concrete implementations. This will help if you decide to change the implementation of your class later to use a different concrete class. In that case the users of your library won't need to update their code since the interface doesn't change.

If you are just using it internally, you may not care so much, and using List may be ok.

Context

Stack Overflow Q#400135, score: 495

Revisions (0)

No revisions yet.