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


C# System.Linq.OrderBy方法代码示例

本文整理汇总了C#中System.Linq.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.OrderBy方法的具体用法?C# System.Linq.OrderBy怎么用?C# System.Linq.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq的用法示例。


在下文中一共展示了System.Linq.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestThenBySelectorPreserved

        public void TestThenBySelectorPreserved()
        {
            var sequence = new[]
                               {
                                   new {A = 2, B = 0},
                                   new {A = 1, B = 5},
                                   new {A = 2, B = 2},
                                   new {A = 1, B = 3},
                                   new {A = 1, B = 4},
                                   new {A = 2, B = 1},
                               };

            var resultA1 = sequence.OrderBy(x => x.A, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, OrderByDirection.Ascending);
            var resultA2 = sequence.OrderBy(x => x.A)
                                   .ThenBy(y => y.B);
            // ensure both produce the same order
            Assert.IsTrue(resultA1.SequenceEqual(resultA2));

            var resultB1 = sequence.OrderBy(x => x.A, OrderByDirection.Ascending)
                                     .ThenBy(y => y.B, OrderByDirection.Descending);
            var resultB2 = sequence.OrderBy(x => x.A)
                                   .ThenByDescending(y => y.B);
            // ensure both produce the same order
            Assert.IsTrue(resultB1.SequenceEqual(resultB2));
        }
开发者ID:KevinKelley,项目名称:morelinq,代码行数:26,代码来源:OrderByTest.cs

示例2: Should_Insert_And_Retrieve_Page_PageContents_Successfully

        public void Should_Insert_And_Retrieve_Page_PageContents_Successfully()
        {
            var page = TestDataProvider.CreateNewPage();

            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(null, page),
                    TestDataProvider.CreateNewPageContent(null, page),
                    TestDataProvider.CreateNewPageContent(null, page)
                };

            page.PageContents = pageContents;
            
            var pageOptions = new[]
                {
                    TestDataProvider.CreateNewPageOption(page),
                    TestDataProvider.CreateNewPageOption(page),
                    TestDataProvider.CreateNewPageOption(page)
                };

            page.Options = pageOptions;

            SaveEntityAndRunAssertionsInTransaction(
                page,
                result =>
                {
                    Assert.AreEqual(page, result);
                    Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                });
        }       
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:30,代码来源:PageMapTest.cs

示例3: TestCommitOrder

        public void TestCommitOrder() {
            var list = new[] {"@cba-1.0.1", "@cba-1.1.1", "@cba-1.1", "@cba-1.0", "@cba-1"};

            var orderedList = list.OrderBy(x => x);

            orderedList.Should().Equal(new[] {"@cba-1", "@cba-1.0", "@cba-1.0.1", "@cba-1.1", "@cba-1.1.1"});
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:7,代码来源:CommitTest.cs

示例4: Test1

        public void Test1()
        {
            var names = new[] {"Pavel", "Alexander", "Anna"};

            IOrderedEnumerable<string> sorted = names.OrderBy(n => n.Length);

            Assert.That(sorted, Is.EqualTo(new[] {"Anna", "Pavel", "Alexander"}));
        }
开发者ID:kontur-edu,项目名称:intern-2014,代码行数:8,代码来源:07-SortAndDistinct.cs

示例5: NaturalSortComparerTest

        public void NaturalSortComparerTest() {
            // Arrange
            var comparer = new NaturalSortComparer();
            var source = new[] { "2name", "1name", "20name", "3name", "11name" };

            // Act
            string[] destination = source.OrderBy(p => p, comparer).ToArray();

            // Assert
            Assert.AreEqual(source.Length, destination.Length);
            Assert.AreEqual("1name", destination[0]);
            Assert.AreEqual("2name", destination[1]);
            Assert.AreEqual("3name", destination[2]);
            Assert.AreEqual("11name", destination[3]);
            Assert.AreEqual("20name", destination[4]);
        }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:16,代码来源:InfrastructureTests.cs

示例6: RemoveVersionSortRemovesThenByWhenVersionIsRepresentedInAWrapperObject

        public void RemoveVersionSortRemovesThenByWhenVersionIsRepresentedInAWrapperObject()
        {
            // Arrange
            var packageAb = new { Id = "A", WrapperObject = new { Version = "B" } };
            var packageAa = new { Id = "A", WrapperObject = new { Version = "A" } };
            var packageAc = new { Id = "A", WrapperObject = new { Version = "C" } };

            var source = new[] { packageAb, packageAc, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.WrapperObject.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.WrapperObject.Version);

            // Assert
            Assert.Equal(new[] { packageAc, packageAb, packageAa }, resultA);
            Assert.Equal(new[] { packageAb, packageAc, packageAa }, resultB);
        }
开发者ID:atrevisan,项目名称:NuGetGallery,代码行数:17,代码来源:ODataRemoveVersionSorterFacts.cs

示例7: NaturalSortingCanBeDoneByPaddingAllTheNumbers

        public void NaturalSortingCanBeDoneByPaddingAllTheNumbers()
        {
            var unsorted = new[]
                         {
                             "10.10.10",
                             "9.9.9"
                         };

            var sorted = unsorted.OrderBy(s => s.PadNumbers(2));

            CollectionAssert.AreEqual(new[]
                                      {
                                          "9.9.9",
                                          "10.10.10"
                                      },
                                      sorted.ToArray());
        }
开发者ID:jdiamond,项目名称:sandbox,代码行数:17,代码来源:NaturalSortingTests.cs

示例8: RemoveVersionSortRemovesThenByWhenItIsNestedInsideAnotherThenBy

        public void RemoveVersionSortRemovesThenByWhenItIsNestedInsideAnotherThenBy()
        {
            // Arrange
            var packageAb = new V2FeedPackage { Id = "A", Version = "B" };
            var packageAa = new V2FeedPackage { Id = "A", Version = "A" };
            var packageAc = new V2FeedPackage { Id = "A", Version = "C" };

            var source = new[] { packageAb, packageAc, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Id).ThenByDescending(p => p.Version);

            // Assert
            Assert.Equal(new[] { packageAc, packageAb, packageAa }, resultA);
            Assert.Equal(new[] { packageAb, packageAc, packageAa }, resultB);
        }
开发者ID:atrevisan,项目名称:NuGetGallery,代码行数:17,代码来源:ODataRemoveVersionSorterFacts.cs

示例9: RemoveVersionSortRemovesThenByOnVersion

        public void RemoveVersionSortRemovesThenByOnVersion()
        {
            // Arrange
            var packageAb = new V2FeedPackage { Id = "A", Version = "B" };
            var packageAa = new V2FeedPackage { Id = "A", Version = "A" };
            var packageCa = new V2FeedPackage { Id = "C", Version = "A" };

            var source = new[] { packageAb, packageCa, packageAa }.AsQueryable();

            // Act
            var resultA = source.OrderBy(p => p.Id).ThenBy(p => p.Version);
            var resultB = source.WithoutVersionSort().OrderBy(p => p.Id).ThenBy(p => p.Version);

            // Assert
            Assert.Equal(new[] { packageAa, packageAb, packageCa }, resultA);
            Assert.Equal(new[] { packageAb, packageAa, packageCa }, resultB);
        }
开发者ID:atrevisan,项目名称:NuGetGallery,代码行数:17,代码来源:ODataRemoveVersionSorterFacts.cs

示例10: Should_Insert_And_Retrieve_Content_PageContents_Successfully

        public void Should_Insert_And_Retrieve_Content_PageContents_Successfully()
        {
            var content = TestDataProvider.CreateNewContent();
            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(content),
                    TestDataProvider.CreateNewPageContent(content)
                };
            content.PageContents = pageContents;

            SaveEntityAndRunAssertionsInTransaction(
                content,
                result =>
                    {
                        Assert.AreEqual(content, result);
                        Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                    });
        }
开发者ID:pmaciulis,项目名称:BetterCMS,代码行数:18,代码来源:ContentMapTest.cs

示例11: Should_Insert_And_Retrieve_Region_PageContentOptions_Successfully

        public void Should_Insert_And_Retrieve_Region_PageContentOptions_Successfully()
        {
            var region = TestDataProvider.CreateNewRegion();

            var pageContents = new[]
                {
                    TestDataProvider.CreateNewPageContent(null, null, region)
                };
            region.PageContents = pageContents;

            SaveEntityAndRunAssertionsInTransaction(
                region,
                result =>
                {
                    Assert.AreEqual(region, result);
                    Assert.AreEqual(pageContents.OrderBy(f => f.Id), result.PageContents.OrderBy(f => f.Id));
                });
        }
开发者ID:pmaciulis,项目名称:BetterCMS,代码行数:18,代码来源:RegionMapTest.cs

示例12: Should_Insert_And_Retrieve_Region_LayoutRegions_Successfully

        public void Should_Insert_And_Retrieve_Region_LayoutRegions_Successfully()
        {
            var region = TestDataProvider.CreateNewRegion();

            var layoutRegions = new[]
                {
                    TestDataProvider.CreateNewLayoutRegion(null, region),
                    TestDataProvider.CreateNewLayoutRegion(null, region)
                };
            region.LayoutRegion = layoutRegions;

            SaveEntityAndRunAssertionsInTransaction(
                region,
                result =>
                {
                    Assert.AreEqual(region, result);
                    Assert.AreEqual(layoutRegions.OrderBy(f => f.Id), result.LayoutRegion.OrderBy(f => f.Id));
                });
        }
开发者ID:pmaciulis,项目名称:BetterCMS,代码行数:19,代码来源:RegionMapTest.cs

示例13: Should_Insert_And_Retrieve_Widget_ContentOptions_Successfully

        public void Should_Insert_And_Retrieve_Widget_ContentOptions_Successfully()
        {
            var widget = TestDataProvider.CreateNewWidget();

            var contentOptions = new[]
                {
                    TestDataProvider.CreateNewContentOption(widget),
                    TestDataProvider.CreateNewContentOption(widget)
                };
            widget.ContentOptions = contentOptions;

            SaveEntityAndRunAssertionsInTransaction(
                widget,
                result =>
                {
                    Assert.AreEqual(widget, result);
                    Assert.AreEqual(contentOptions.OrderBy(f => f.Id), result.ContentOptions.OrderBy(f => f.Id));
                });
        }
开发者ID:wezmag,项目名称:BetterCMS,代码行数:19,代码来源:WidgetMapTest.cs

示例14: Should_Insert_And_Retrieve_Layout_Pages_Successfully

        public void Should_Insert_And_Retrieve_Layout_Pages_Successfully()
        {
            var layout = TestDataProvider.CreateNewLayout();
            var pages = new[]
                {
                    TestDataProvider.CreateNewPage(layout),
                    TestDataProvider.CreateNewPage(layout),
                    TestDataProvider.CreateNewPage(layout)
                };
            layout.Pages = pages;

            SaveEntityAndRunAssertionsInTransaction(
                layout,
                result =>
                    {
                        Assert.AreEqual(layout, result);
                        Assert.AreEqual(pages.OrderBy(f => f.Id), result.Pages.OrderBy(f => f.Id));
                    });
        }
开发者ID:wezmag,项目名称:BetterCMS,代码行数:19,代码来源:LayoutMapTest.cs

示例15: Should_Insert_And_Retrieve_PageProperties_PageTags_Successfully

        public void Should_Insert_And_Retrieve_PageProperties_PageTags_Successfully()
        {
            var page = TestDataProvider.CreateNewPageProperties();

            var pageTags = new[]
                {
                    TestDataProvider.CreateNewPageTag(page),
                    TestDataProvider.CreateNewPageTag(page),
                    TestDataProvider.CreateNewPageTag(page)
                };

            page.PageTags = pageTags;

            SaveEntityAndRunAssertionsInTransaction(
                page,
                result =>
                {
                    Assert.AreEqual(page, result);
                    Assert.AreEqual(pageTags.OrderBy(f => f.Id), result.PageTags.OrderBy(f => f.Id));
                });
        }
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:21,代码来源:PagePropertiesMapTest.cs


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