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


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

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


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

示例1: Test

        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var words = new string[] { "ab2", "ac", "a", "ab12", "", "ab", "bac", "z" };
            var sortedWords = (from word in words
                               orderby word
                               select word).ToArray();
            assert.DeepEqual(sortedWords, new[] { "", "a", "ab", "ab12", "ab2", "ac", "bac", "z" }, "Order by words");

            // TEST
            var sortedWordsByLength = (from word in words
                                       orderby word.Length
                                       select word).ToArray();
            assert.DeepEqual(sortedWordsByLength, new[] { "", "a", "z", "ac", "ab", "ab2", "bac", "ab12" }, "Order by word length");

            // TEST
            var sortedPersonsByName = (from p in Person.GetPersons()
                                       orderby p.Name
                                       select p.Name).ToArray();
            assert.DeepEqual(sortedPersonsByName, new[] { "Billy", "Dora", "Frank", "Ian", "John", "Mary", "Nemo", "Zeppa" }, "Order by person names");

            // TODO test with System.StringComparison

            // TEST
            var doubles = new double[] { 1.0, -0.7, 2.1, 0.9, 1.4, 2.9 };
            var sortedDoubles = (from d in doubles
                                 orderby d descending
                                 select d).ToArray();
            assert.DeepEqual(sortedDoubles, new[] { 2.9, 2.1, 1.4, 1.0, 0.9, -0.7 }, "Order by descending double");

            // TEST
            var sortedPersonsByCountDesc = (from p in Person.GetPersons()
                                            orderby p.Count descending
                                            select p.Count).ToArray();
            assert.DeepEqual(sortedPersonsByCountDesc, new[] { 3000, 700, 700, 550, 500, 300, 100, 50 }, "Order by person count descending");

            // TEST
            var sortedWordsByLengthAndLetters = (from word in words
                                                 orderby word.Length, word
                                                 select word).ToArray();
            assert.DeepEqual(sortedWordsByLengthAndLetters, new[] { "", "a", "z", "ab", "ac", "ab2", "bac", "ab12" }, "Order by word length then by letters");

            // TEST
            var sortedWordsByLengthAndLettersLambda = words.OrderBy(x => x.Length).ThenByDescending(x => x).ToArray();
            assert.DeepEqual(sortedWordsByLengthAndLettersLambda, new[] { "", "z", "a", "ac", "ab", "bac", "ab2", "ab12" }, "Order by word length then by letters as lambda");

            // TEST
            // var numbers = new[] { 2, 4, 6, 1, 5, 7, 9, 0, 8, 3};
            var numbers = new[] { 2, 4, 6, 1, 5 };
            var numbersReversed = numbers.Reverse<int>().ToArray();
            assert.DeepEqual(numbersReversed, new[] { 5, 1, 6, 4, 2 }, "Reverse() numbers");
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:54,代码来源:TestLinqOrderingOperators.cs

示例2: InvertRun

 public void InvertRun()
 {
     var seq = new[] {0, 1, 2, 3, 4, 5};
     var handler = new SequenceHandler<int>(seq)
                   {
                       Reverse = true
                   };
     var inverted = seq.Reverse().ToArray();
     Assert.AreEqual(handler.Count, seq.Length);
     for (int i = 0; i < handler.Count; i++)
     {
         Assert.AreEqual(inverted[i], handler[i]);
     }
 }
开发者ID:eocron,项目名称:ORegex,代码行数:14,代码来源:SequenceHandlerTests.cs

示例3: FastReverseTest

 public void FastReverseTest()
 {
     var data = new[] { 1, 2, 3, 4, 5 };
     Expect(data.FastReverse(), EquivalentTo(data.Reverse()));
     Expect(data, EquivalentTo(data.FastReverse().Reverse()));
 }
开发者ID:stewshka,项目名称:Suigetsu,代码行数:6,代码来源:ListExtensionsTests.cs


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