Rick
Rick

Reputation: 57

Which interface do I have to implement for an item collection

Class: Episode with properties string name, uint orderNumber and timespan length.
Class: TVserie with episodes[] property.

How do I make something like this:

TVseries breakingBad = new TVseries();
breakingBad.episodes.add(511, "Confessions", 30.00);

Which Interface provides the 'add' and other collection functionality to my custom classes?

==============================

Edit: thanks! I changed it to:

List<Episode> breakingBadSeason5 = new List<Episode>();
Episode episode = new Episode();
episode.Name = "confessions";
breakingBadSeason5.Add(episode);

Upvotes: 0

Views: 86

Answers (1)

Haedrian
Haedrian

Reputation: 4328

You don't want an Episodes[] property - since arrays are non resizable.

Use a List<Episodes> instead. Then you can add all you like.

To answer your question however, the interface is ICollection<T>

Full answer:

public class TVSerie
{
public List<Episode> Episodes{get;set;}

public TVSerie ()
{
   this.Episodes = new List<Episode>
}

}

TVserie breakingBad = new TVserie();
Episode episode = new Episode();
episode.Foo = "Foo";
episode.Bar = "Bar";
breakingBad.Episodes.Add(episode);

Upvotes: 1

Related Questions