的所有實現我要求一個更加流暢和漂亮的方式(如果我錯了這裏和/或修正)要做到這一點,填寫一個HashSet <T>與ISomething
HashSet<ISomething> itemRows;
List<ISomething> PopulateItemRows()
{
itemRows = new HashSet<ISomething>();
itemRows.UnionWith(new SomeType1().Collection());
itemRows.UnionWith(new SomeType2().Collection());
itemRows.UnionWith(new SomeType3().Collection());
itemRows.UnionWith(new SomeType4().Collection());
return itemRows.ToList();
}
SomeTypeXX都實現了ISomething 。
最好的當然是避免顯式包括類型。 可能存在新實現的情況,並且此方法未能更新。
更正1:'PopulateItemRows'預計返回void,但您的返回語句返回一個列表。簽名應該是'公開名單 PopulateItemRows()' –
2011-04-08 07:51:34
當然。由一些編輯引起的。感謝您的糾正。現在,只有一些建議是錯過:)。 – Independent 2011-04-08 07:54:57