本文整理汇总了C#中IEnumerable.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.OrderBy方法的具体用法?C# IEnumerable.OrderBy怎么用?C# IEnumerable.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateList
public async Task<IEnumerable<ParkingLot>> CreateList(IEnumerable<ParkingLot> items)
{
var mainVm = ServiceLocator.Current.GetInstance<MainViewModel>();
var filter = mainVm.ParkingLotFilterMode;
var orderAsc = mainVm.ParkingLotFilterAscending;
var alphabeticalSortingFunc = new Func<ParkingLot, string>(x => x.Name);
switch (filter)
{
case ParkingLotFilterMode.Alphabetically:
return orderAsc ? items.OrderBy(alphabeticalSortingFunc) : items.OrderByDescending(alphabeticalSortingFunc);
case ParkingLotFilterMode.Availability:
var availabilitySortingFunc = new Func<ParkingLot, double>(x =>
{
if (x.TotalLots == 0)
{
return 2; //they're always last of the list
}
return 1 - ((double) x.FreeLots / (double)x.TotalLots); //something between 0 and 1
});
return orderAsc ? items.OrderBy(availabilitySortingFunc).ThenBy(alphabeticalSortingFunc) : items.OrderByDescending(availabilitySortingFunc).ThenBy(alphabeticalSortingFunc);
case ParkingLotFilterMode.Distance:
var userPos = await ServiceLocator.Current.GetInstance<GeolocationService>().GetUserLocation();
if (userPos == null)
{
mainVm.ParkingLotFilterMode = ParkingLotFilterMode.Alphabetically;
return await CreateList(items);
}
var distanceSortingFunc = new Func<ParkingLot, double>(x => x?.Coordinates?.Point == null ? double.MaxValue : userPos.Coordinate.Point.GetDistanceTo(x.Coordinates.Point));
return orderAsc ? items.OrderBy(distanceSortingFunc).ThenBy(alphabeticalSortingFunc) : items.OrderByDescending(distanceSortingFunc).ThenBy(alphabeticalSortingFunc);
default:
return orderAsc ? items.OrderBy(alphabeticalSortingFunc) : items.OrderByDescending(alphabeticalSortingFunc);
}
}
示例2: GetClosestBy
private Player GetClosestBy(IEnumerable<Player> queue)
{
var sorted = queue.OrderBy(q => GetDistanceToGoalSquared(q.Position)).ToList();
return queue
.OrderBy(q => GetDistanceToGoalSquared(q.Position))
.FirstOrDefault();
}
示例3: CheckSortOrder
//Check the Sort Order to sort with corresponding column
public void CheckSortOrder(string sortOrder, ref IEnumerable<Comment> comment)
{
switch (sortOrder)
{
case "Date_desc":
comment = comment.OrderByDescending(u => u.PostedDate);
break;
case "PatientName":
comment = comment.OrderBy(u => u.Patient.FullName);
break;
case "PatientName_desc":
comment = comment.OrderByDescending(u => u.Patient.FullName);
break;
case "DoctorName":
comment = comment.OrderBy(u => u.Doctor.FullName);
break;
case "DoctorName_desc":
comment = comment.OrderByDescending(u => u.Doctor.FullName);
break;
case "Content":
comment = comment.OrderBy(u => u.Content);
break;
case "Content_desc":
comment = comment.OrderByDescending(u => u.Content);
break;
default:
comment = comment.OrderBy(u => u.PostedDate);
break;
}
}
示例4: FilterModel
private IEnumerable<SourceModel> FilterModel(IEnumerable<SourceModel> model)
{
var ret = model;
var order = _content.Filter.OrderBy;
if (order == SourceFilterModel.Order.Alphabetical)
ret = model.OrderBy(x => x.Name);
else if (order == SourceFilterModel.Order.FoldersThenFiles)
ret = model.OrderBy(x => x.Type).ThenBy(x => x.Name);
return _content.Filter.Ascending ? ret : ret.Reverse();
}
示例5: OrderAscending
public static IEnumerable<Country> OrderAscending(IEnumerable<Country> countries, Culture culture)
{
switch (culture)
{
case Culture.Ru:
return countries.OrderBy(x => x.Translation.Ru);
default:
return countries.OrderBy(x => x.Translation.En);
}
}
示例6: getList
public IPagedList<Facility> getList(string sortOrder, string currentFilter, int? page, IEnumerable<Facility> data)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.Name = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
ViewBag.IsFree = sortOrder == "IsFree" ? "IsFree_desc" : "IsFree";
ViewBag.Enabled = sortOrder == "Enabled" ? "Enabled_desc" : "Enabled";
ViewBag.SO_RateTypeId = sortOrder == "RateTypeId" ? "RateTypeId_desc" : "RateTypeId";
ViewBag.Rate = sortOrder == "Rate" ? "Rate_desc" : "Rate";
ViewBag.IsGST = sortOrder == "IsGST" ? "IsGST_desc" : "IsGST";
switch (sortOrder)
{
case "Name_desc":
data = data.OrderByDescending(s => s.Name );
break;
case "IsFree":
data = data.OrderBy(s => s.IsFree);
break;
case "IsFree_desc":
data = data.OrderByDescending(s => s.IsFree);
break;
case "Enabled":
data = data.OrderBy(s => s.Enabled);
break;
case "Enabled_desc":
data = data.OrderByDescending(s => s.Enabled);
break;
case "RateTypeId":
data = data.OrderBy(s => s.RateTypeId);
break;
case "RateTypeId_desc":
data = data.OrderByDescending(s => s.RateTypeId);
break;
case "Rate":
data = data.OrderBy(s => s.Rate);
break;
case "Rate_desc":
data = data.OrderByDescending(s => s.Rate);
break;
case "IsGST":
data = data.OrderBy(s => s.IsGST);
break;
case "IsGST_desc":
data = data.OrderByDescending(s => s.IsGST);
break;
case "":
default:
data = data.OrderBy(s => s.Name);
break;
}
int pageSize = Configurations.PageSize();
int pageNumber = (page ?? 1);
return data.ToPagedList(pageNumber, pageSize);
}
示例7: Order
private static string[] Order(IEnumerable<string> fileSystemEntries)
{
try
{
// take in account that "2-someMigration" should go before "11-someOtherMigration"
return fileSystemEntries.OrderBy(x => MigrationManager.GetMigrationId(Path.GetFileNameWithoutExtension(x))).ToArray();
}
catch (FormatException)
{
return fileSystemEntries.OrderBy(x => x).ToArray();
}
}
示例8: Median
public static double Median(IEnumerable<double> myNumbers)
{
if (myNumbers.Count() == 0)
throw new InvalidOperationException("Invalid count of numbers... must be greater that zero!");
if (myNumbers.Count() % 2 == 0)
{
return myNumbers.OrderBy(_ => _).Skip(myNumbers.Count() / 2 - 1).Take(2).Sum() / 2;
}
else
{
return myNumbers.OrderBy(_ => _).ElementAt((int)Math.Floor((decimal)(myNumbers.Count() / 2)));
}
}
示例9: SetMessageOrder
private Queue<Message> SetMessageOrder(IEnumerable<Message> unorderedMessages)
{
var messages = new Queue<Message>(
unorderedMessages.OrderBy(x => x.MessengerOrderId));
return messages;
}
示例10: LoadWidgets
public void LoadWidgets(IEnumerable<Widget> widgetModels, Control placeholder, TemplateControl page)
{
if (placeholder == null)
{
return;
}
if (page == null)
{
return;
}
if (widgetModels == null)
{
return;
}
var groups = widgetModels.OrderBy(x => x.RowNumber).ThenBy(x => x.ColumnNumber).GroupBy(x => new {x.RowNumber});
foreach (var group in groups)
{
foreach (Widget item in group)
{
using (MixERPWidgetBase widget = page.LoadControl(item.WidgetSource) as MixERPWidgetBase)
{
if (widget != null)
{
placeholder.Controls.Add(widget);
widget.OnControlLoad(widget, new EventArgs());
}
}
}
}
}
示例11: RepoConfig
internal RepoConfig(
IEnumerable<NuGetPackage> fixedPackages,
IEnumerable<string> toolsetPackages,
IEnumerable<Regex> nuspecExcludes,
IEnumerable<Regex> projectJsonExcludes,
GenerateData? msbuildGenerateData)
{
Debug.Assert(toolsetPackages.Distinct().Count() == toolsetPackages.Count());
MSBuildGenerateData = msbuildGenerateData;
FixedPackages = fixedPackages.OrderBy(x => x.Name).ToImmutableArray();
NuSpecExcludes = nuspecExcludes.ToImmutableArray();
ProjectJsonExcludes = projectJsonExcludes.ToImmutableArray();
ToolsetPackages = toolsetPackages.OrderBy(x => x).ToImmutableArray();
var map = new Dictionary<string, List<string>>();
foreach (var nugetRef in fixedPackages)
{
List<string> list;
if (!map.TryGetValue(nugetRef.Name, out list))
{
list = new List<string>(capacity: 1);
map[nugetRef.Name] = list;
}
list.Add(nugetRef.Version);
}
}
示例12: GetContent
private static string GetContent(IEnumerable<Notification> notifications)
{
return notifications
.OrderBy(x => x.Date)
.Aggregate(new StringBuilder(), (s, notification) => s.AppendLine(notification.Content).AppendLine().AppendLine("----------").AppendLine())
.ToString();
}
示例13: MatchApplicablePromotions
public IEnumerable<PromotionMatch> MatchApplicablePromotions(PriceCalculationContext context, IEnumerable<Promotion> candidatePromotions)
{
var matches = new List<PromotionMatch>();
// Lower priority promotions check first
candidatePromotions = candidatePromotions.OrderBy(x => x.Priority).ThenBy(x => x.Id);
foreach (var promotion in candidatePromotions)
{
var match = TryMatchPromotion(promotion, context);
if (match != null)
{
matches.Add(match);
}
}
if (matches.Count > 0)
{
// Higher priority check first
matches.Reverse();
CheckOverlappingUsage(matches);
}
return matches;
}
示例14: ParseMethods
private void ParseMethods(IEnumerable<SDMethod> methods)
{
foreach (var method in methods.OrderBy(o => o.Name))
{
_classDiagram.MethodRows.Add(new ClassDiagramRow(method.Identifier, "Method", method.Accessibility, method.Name));
}
}
示例15: Visit
public override string Visit(IEnumerable<Item> items, string current)
{
if(current.IndexOf(TOKEN) < 0)
return current;
return current.Replace(TOKEN, runFilter<ProphecyFilter>(items.OrderBy(i => i.H)));
}