本文整理匯總了C#中Category.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# Category.Select方法的具體用法?C# Category.Select怎麽用?C# Category.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Category
的用法示例。
在下文中一共展示了Category.Select方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: getCategoriesByTitleFilteringToOne
private static CategoryCollection getCategoriesByTitleFilteringToOne(List<Category> currentCategories, Category[] sourceCategories)
{
CategoryCollection result = new CategoryCollection();
var sourceTitles = sourceCategories.Select(cat => cat.CategoryName).ToArray();
var categoriesToSet = sourceTitles.Select(title => currentCategories.FirstOrDefault(cat => cat.Title == title))
.Where(cat => cat != null);
result.CollectionContent.AddRange(categoriesToSet);
if (result.CollectionContent.Count > 1)
{
bool removeProject = false;
bool removeNews = false;
if (result.CollectionContent.Any(cat => cat.Title == "Events"))
{
removeProject = true;
removeNews = true;
}
if (result.CollectionContent.Any(cat => cat.Title == "Projects"))
{
removeNews = true;
}
result.CollectionContent.RemoveAll(cat =>
{
if ((cat.Title == "News" && removeNews) || (cat.Title == "Projects" && removeProject))
return true;
return false;
});
}
return result;
}