When planning out my programs, I often start with a chain of thought like so:
A football team is just a list of football players. Therefore, I should
Wow, your post has an entire slew of questions and points. Most of the reasoning you get from Microsoft is exactly on point. Let's start with everything about List
List
is highly optimized. Its main usage is to be used as a private member of an object.class MyList : List> { ... }
. Now it's as easy as doing var list = new MyList();
.IList
if you need any consumer to have an indexed list. This lets you change the implementation within a class later on.Collection
very generic because it is a generic concept... the name says it all; it is just a collection. There are more precise versions such as SortedCollection
, ObservableCollection
, ReadOnlyCollection
, etc. each of which implement IList
but not List
.Collection
allows for members (i.e. Add, Remove, etc.) to be overridden because they are virtual. List
does not.If I were writing this code, the class would probably look something like so:
public class FootballTeam
{
// Football team rosters are generally 53 total players.
private readonly List _roster = new List(53);
public IList Roster
{
get { return _roster; }
}
// Yes. I used LINQ here. This is so I don't have to worry about
// _roster.Length vs _roster.Count vs anything else.
public int PlayerCount
{
get { return _roster.Count(); }
}
// Any additional members you want to expose/wrap.
}