2013-08-31 33 views
0
Class: Episode with properties string name, uint orderNumber and timespan length. 
Class: TVserie with episodes[] property. 

如何让这样的事情:哪个接口来实现一个项目集合

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

哪个接口提供的“添加”和其他集合功能,我的自定义类?

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

编辑:谢谢!我将其更改为:

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

1)'add'应该大写2)参见['ICollection的。新增'方法](http://msdn.microsoft.com/zh-cn/library/63ywd54z.aspx)MSDN – CodesInChaos

+0

'uint'不在CLS中;使用'int'或'long'。或者考虑使用字符串作为订单号。这不像你会对它做数学。 –

回答

1

您不想要Episodes[]属性 - 因为数组不可调整大小。

改为使用List<Episodes>。然后你可以添加你喜欢的所有东西。

然而,为了回答你的问题,界面ICollection<T>

完整的答案:

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); 
+0

数组* *不可调整大小*我想你的意思是说。 –

+0

你说得对。固定。 – Haedrian

+0

你的链接是'IList ',而不是'ICollection',我想你的意思是'ICollection '。 –