0

I need help, I know that in C# we have Data-collections containers, like:

  • Dictionary
  • SortedDictionary
  • SortedList
  • List
  • LinkedList
  • HashSet
  • And so on

But I've seen functions which return or take input parameters IEnumerable.

public IEnumerable<Cars> GetCars()
{

}

What is above function returning, What Data collection Type ,container ? ???...IEnumerable is not data collection container.??

I think i also have seen Interfaces used like this.

IEnumerable xList = new List();
IEnumerable D = new Dictionary();
IEnumerable L = new List();

Ilist p = new Hash();    < - Is this COrrect ?

What datacollection they returning ?

Why do people use Interface to return or hold data ?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
LalA
  • 37
  • 5
  • Welcome to Stack Overflow. When you post, please pay more attention to the formatting of your post - use the preview to make sure that the code looks exactly how you'd want it to before posting, bearing in mind that the primary goal of Stack Overflow is to create a repository of high-quality questions and answers. – Jon Skeet Nov 18 '16 at 07:35
  • The whole point of such methods returning interfaces is that *they're not committing to which container they happen to be using in their current implementation*. They may change the concrete implementation to a different container later and they haven't broken any promises they've made to you, the consumer. All they promised is that they'll return *something* that's e.g. enumerable. – Damien_The_Unbeliever Nov 18 '16 at 07:44

0 Answers0