私は理解しようとしているこのクラスを持っています:
public class Track
{
public string Title { get; set; }
public uint Length { get; set; }
public Album Album { get; internal set; }
}
public class Album : Collection<Track>
{
protected override void InsertItem(int index, Track item)
{
base.InsertItem(index, item);
item.Album = this;
}
protected override void SetItem(int index, Track item)
{
base.SetItem(index, item);
item.Album = this;
}
protected override void RemoveItem(int index)
{
this[index].Album = null;
base.RemoveItem(index);
}
protected override void ClearItems()
{
foreach (Track track in this)
{
track.Album = null;
}
base.ClearItems();
}
}
新しい変数を割り当てた後、base.InsertItem を使用するのはなぜですか? base.InsertItem とその他 (アイテムの設定、削除、クリア) を省略しても問題ありません。
私は私の質問について十分に明確ではなかったと思います。
私の意見では、 base.InsertItem コレクションにアイテムを追加するのは Collections メソッドです。すでに追加しているのであれば、なぜこれを item.Album に割り当てているのでしょうか。
Track クラスにある Album と Collection を使用している Album クラスについて少し混乱しています。
このコレクションの使用例を誰かに見せてもらえますか?
ありがとう!