【发布时间】:2014-09-19 18:32:01
【问题描述】:
我需要优化我的代码。我有一些重复代码。但我想优化它。谁能帮我优化我的代码。我怎样才能为此增加通用功能???
foreach (var item in hotellocation.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count()))
{
if (item.Key != "")
{
lstHotelLocation.Add(new HotelLocation()
{
Name = item.Key,
count = item.Value
});
}
}
//need to Apply to linq
foreach (var item in hoteltype.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count()))
{
if (item.Key != "")
{
lstHotelType.Add(new HotelTypeFilter()
{
Name = item.Key,
count = item.Value
});
}
}
【问题讨论】:
-
我要摆脱的第一件事是
ToDictionary- 它毫无意义,因为您从来没有将它用作字典。
标签: c# asp.net-mvc linq optimization