If I have a function that takes a collection of a certain type, what parameter type should I use?
I have previously assumed IEnumerable is the default, but I would like to know if this is correct and if so, why.
ICollection also seems like a valid candidate (due to its name), but I get the impression IEnumerables are more user friendly.
I figured looking at examples the framework gives us would be a good idea, but I find that something like String.Join, asks for an array of strings.
If I have a function that takes a collection of a certain type, what
Share
You take the one that imposes the least on clients but allows you to get your job done. If you can get away with
IEnumerable<T>overICollection<T>, then you should use it because this gives greater flexibility to clients of your API.