0

Possible Duplicate:
C# - List<T> or IList<T>

I'm working on a solution have noticed there is a lot fo IList being implemented. Just wondering, what is the point of using an IList when you can use a List?

Community
  • 1
  • 1
Funky
  • 12,890
  • 35
  • 106
  • 161
  • Found a link to the same question: http://stackoverflow.com/questions/400135/c-listt-or-ilistt – David Jul 27 '11 at 09:09
  • please provide a specific question for a specific answer. – Jodrell Jul 27 '11 at 09:11
  • The duplicate is the first result (ignoring this one) that you get in 'related questions', when you try to ask this as well... ;) Which is why you ask your QUESTION in the title, and explain any DETAILS in the description box... – J. Steen Jul 27 '11 at 09:12

3 Answers3

1

Because some collections may inherit from IList and not from List, ObservableCollection for example.

Bob Vale
  • 18,094
  • 1
  • 42
  • 49
1

If you want don't want to inherit List and just want to implement the interface use IList.

Perhaps you want to return an object that supports IList but the implementation is irrelavant to the caller?

In your case implementing IList may result in unesscessary typing, it may be right thing to do, I' can't know without more info.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
1

You should always try to use the interface where possible to allow the user to have more flexibility on which implementation they use. Generally, IEnumerable and IQueryable are even better than IList as they're more generic, unless you want to limit this with good reason of course.

Chris Snowden
  • 4,982
  • 1
  • 25
  • 34