的所有实现我要求一个更加流畅和漂亮的方式(如果我错了这里和/或修正)要做到这一点,填写一个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