You are recursively calling the property indexer an infinite number of times. I think you want this:
public Tracks this[int i]
{
get
{
return (Tracks) List[i];
}
set
{
List[i] = value;
}
}
Then, add your items:
TrackList l1 = new TrackList();
l1.List.Add(new Tracks(1, "Random"));
l1.List.Add(new Tracks(2, "Random"));
l1.List.Add(new Tracks(3, "Random"));
Then replace an item using the indexer:
l1[1] = new Tracks(2, "Replacement");
Or retrieve an item using the indexer:
var firstItem = l1[0];
Trying to use l1[i]
where i <= l1.Count
will produce an ArgumentOutOfRangeException
, as you would expect.