我还在学习LINQ
所以忍受我:)。我的问题是,如何将以下代码转换为LINQ
int count = 0;
foreach (var item in settings.FavouritesSetting)
{
if (item.FavouriteType != Constants.FavouriteType.Folder)
count++;
}
return count.ToString();
答案 0 :(得分:11)
var count = settings.FavouritesSetting.Count(i => i.FavouriteType != Constants.FavouriteType.Folder);
return count.ToString();
答案 1 :(得分:0)
var count = (from item in settings.FavouritesSetting
where item.FavouriteType != Constants.FavouriteType.Folder
select item).Count();
return count.ToString();