本文整理汇总了C#中IGrouping.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IGrouping.FirstOrDefault方法的具体用法?C# IGrouping.FirstOrDefault怎么用?C# IGrouping.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGrouping
的用法示例。
在下文中一共展示了IGrouping.FirstOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCategory
private ICategory GetCategory(string phase, IGrouping<string, ICategory> group)
{
return group.FirstOrDefault(x =>
{
if (x.Name.Length < phase.Length) return false;
var part = x.Name.Substring(0, phase.Length);
return string.Equals(part, phase, StringComparison.OrdinalIgnoreCase);
});
}
示例2: OnStockProductViewModel
//public OnStockProductViewModel(Product product): base(product)
//{
// var orderedTransactions = product.Transactions.OrderBy(x => x.Date);
// var transactionBought = orderedTransactions.LastOrDefault(x => x.TypeID == (int) TranType.Bought);
// if (transactionBought != null)
// {
// DateBought = transactionBought.Date;
// SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman);
// }
// var lastTransaction = orderedTransactions.LastOrDefault();
// if (lastTransaction != null)
// {
// LastTransactionDate = lastTransaction.Date;
// }
//}
public OnStockProductViewModel(IGrouping<ModelSerialNumberStatusPriceBoughtGroup, Product> products)
: base(products.FirstOrDefault())
{
IDs = products.Select(x => x.ID).ToList();
Product firstProduct = products.FirstOrDefault();
if (firstProduct == null) return;
var orderedTransactions = firstProduct.Transactions.OrderBy(x => x.Date);
var transactionBought =
orderedTransactions.LastOrDefault(x => x.TypeID == (int) TranType.Bought);
if (transactionBought != null)
{
DateBought = transactionBought.Date;
SalesmanBought = new SalesmanViewModel(transactionBought.Operator.Salesman);
}
var lastTransaction = orderedTransactions.LastOrDefault();
if (lastTransaction != null)
{
LastTransactionDate = lastTransaction.Date;
}
}
示例3: CreateModuleDefinition
private static ModuleDefinition CreateModuleDefinition(IGrouping<string, TemplateInfo> t)
{
var moduleId = GetModuleId(t.Key);
var defaultTemplateCandidates = GetDefaultTemplateCandidates(moduleId);
var defaultTemplate = t.FirstOrDefault(a => defaultTemplateCandidates.Contains(a.Id));
var templates = t.ToList();
if (defaultTemplate == null && templates.Count == 1)
defaultTemplate = templates[0];
var skins = templates.Where(t1 => t1 != defaultTemplate).ToDictionary(GetSkinName);
if (defaultTemplate == null && skins.TryGetValue(string.Empty, out defaultTemplate))
skins.Remove(string.Empty);
return new ModuleDefinition(moduleId, defaultTemplate, skins);
}