本文整理汇总了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");
}
示例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]);
}
}
示例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()));
}