我从某种来源获得物品(从其他地点收集):
public class ItemsFromSource{
public ItemsFromSource(string name){
this.SourceName = name;
Items = new List<IItem>();
}
public string SourceName;
public List<IItem> Items;
}
现在,MyClass 我从几个来源获得物品(从其他地方收集):
public class MyClass{
public MyClass(){
}
public List<ItemsFromSource> BunchOfItems;
}
Is there a simple way to iterate through all Items in all ItemsFromSources in BunchOfItems in one go? i.e., something like:
foreach(IItem i in BunchOfItems.AllItems()){
// do something with i
}
不这样做
foreach(ItemsFromSource ifs in BunchOffItems){
foreach(IItem i in ifs){
//do something with i
}
}