-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
Reverse-Sample-1.cs
52 lines (47 loc) · 1.83 KB
/
Reverse-Sample-1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Linq;
namespace Ordering
{
public class Reverse1
{
//This sample uses Reverse to create a list of all digits in the array whose
// second letter is 'i' that is reversed from the order in the original array.
//Outputs to the console:
// A backwards list of the digits with a second character of 'i':
// nine
// eight
// six
// five
public static void QuerySyntaxExample()
{
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var reversedIDigits = ( from d in digits
where d[1] == 'i'
select d
).Reverse();
Console.WriteLine("A backwards list of the digits with a second character of 'i':");
foreach (var d in reversedIDigits)
{
Console.WriteLine(d);
}
}
//This sample uses Reverse to create a list of all digits in the array whose
// second letter is 'i' that is reversed from the order in the original array.
//Outputs to the console:
// A backwards list of the digits with a second character of 'i':
// nine
// eight
// six
// five
public static void MethodSyntaxExample()
{
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var reversedIDigits = digits.Where(d => d[1]=='i').Reverse();
Console.WriteLine("A backwards list of the digits with a second character of 'i':");
foreach (var d in reversedIDigits)
{
Console.WriteLine(d);
}
}
}
}