当前位置: 首页>>代码示例>>C#>>正文


C# IEnumerable.OrderBy方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:sibbl,项目名称:ParkenDD,代码行数:34,代码来源:ParkingLotListFilterService.cs

示例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();
		}
开发者ID:Corniel,项目名称:Cloudball.Toothless,代码行数:7,代码来源:Keeper.cs

示例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;
     }
 }
开发者ID:palaniellappank,项目名称:online-medical-consultant-system,代码行数:31,代码来源:AdminCommentBusiness.cs

示例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();
        }
开发者ID:vbassini,项目名称:CodeBucket,代码行数:10,代码来源:SourceTreeViewModel.cs

示例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);
     }
 }
开发者ID:Reidan94,项目名称:ITouristDashboard,代码行数:10,代码来源:Country.Extensions.cs

示例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);
        }
开发者ID:DureSameen,项目名称:RoomReservation2,代码行数:54,代码来源:FacilitiesController.cs

示例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();
     }
 }
开发者ID:raoulmillais,项目名称:DatabaseMigraine,代码行数:12,代码来源:Program.cs

示例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)));
            }
        }
开发者ID:sones,项目名称:benchmark,代码行数:14,代码来源:Statistics.cs

示例9: SetMessageOrder

        private Queue<Message> SetMessageOrder(IEnumerable<Message> unorderedMessages)
        {
            var messages = new Queue<Message>(
                unorderedMessages.OrderBy(x => x.MessengerOrderId));

            return messages;
        }
开发者ID:billboga,项目名称:dnxflash,代码行数:7,代码来源:QueueMessenger.cs

示例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());
                        }
                    }
                }
            }
        }
开发者ID:JonathanValle,项目名称:mixerp,代码行数:34,代码来源:Index.aspx.cs

示例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);
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:27,代码来源:RepoConfig.cs

示例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();
		}
开发者ID:kruglik-alexey,项目名称:jeegoordah,代码行数:7,代码来源:NotificationsSender.cs

示例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;
        }
开发者ID:Kooboo,项目名称:Ecommerce,代码行数:25,代码来源:PromotionMatcher.cs

示例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));
     }
 }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:7,代码来源:ClassDiagramParser.cs

示例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)));
        }
开发者ID:mihailim,项目名称:Procurement,代码行数:7,代码来源:ProphecyVisitor.cs


注:本文中的IEnumerable.OrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。