2

我还在学习LINQ,所以请耐心等待:)。我的问题,如何将以下代码转换为LINQ

int count = 0;

foreach (var item in settings.FavouritesSetting)
{
   if (item.FavouriteType != Constants.FavouriteType.Folder)
      count++;
}

return count.ToString();
4

2 回答 2

11
var count = settings.FavouritesSetting.Count(i => i.FavouriteType != Constants.FavouriteType.Folder);

return count.ToString();
于 2013-05-19T09:41:23.983 回答
0
var count = (from item in settings.FavouritesSetting
            where item.FavouriteType != Constants.FavouriteType.Folder
            select item).Count();
return count.ToString();
于 2013-05-19T09:43:57.300 回答