-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (52 loc) · 2.74 KB
/
Program.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching
// https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns
int[] fibonacci = { 1, 2, 3, 5, 8 };
bool result = false;
// result is false, last number is not matching
result = fibonacci is [1, 2, 3, 5, 9];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, 2, 3, 5, 9] = {result}");
// result is false, elements are not at same positions
result = fibonacci is [8, 1, 2, 3, 5];
Console.WriteLine($"[1, 2, 3, 5, 9] is [8, 1, 2, 3, 5] = {result}");
// result is false, length is not matching
result = fibonacci is [1, 2, 3, 5];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, 2, 3, 5] = {result}");
// result is true, elements, positions and length is matching
result = fibonacci is [1, 2, 3, 5, 8];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, 2, 3, 5, 8] = {result}");
// result is false, length not matching
result = fibonacci is [_, _, 3, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [_, _, 3, _] = {result}");
// result is false, 3 is not at same position
result = fibonacci is [_, _, _, 3, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [_, _, _, 3, _] = {result}");
// result is false, length is matching but 2 and 3 not at same positions
result = fibonacci is [2, _, 3, _, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [2, _, 3, _, _] = {result}");
// result is true, single element and its position and length is matching
result = fibonacci is [1, _, _, _, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, _, _, _, _] = {result}");
// result is true, multiple elements and their positions and length is matching
result = fibonacci is [1, _, 3, _, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, _, 3, _, _] = {result}");
// result is true, as fibonacci ends with element 8
result = fibonacci is [.., 8];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, _, 3, _, _] = {result}");
// result is false, 3 is not second last element
result = fibonacci is [.., 3, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, _, 3, _, _] = {result}");
// result is true, as sequence begins with 1 and ends with 8
result = fibonacci is [1, .., 8];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, .., 8] = {result}");
// result is true, as 1 is first element
result = fibonacci is [1, ..];
Console.WriteLine($"[1, 2, 3, 5, 9] is [1, ..] = {result}");
// result is false, as fibonacci ends with element 8
result = fibonacci is [.., <8];
Console.WriteLine($"[1, 2, 3, 5, 9] is [.., <8] = {result}");
// result is true, 3 is third element from the ending
result = fibonacci is [.., >= 3, _, _];
Console.WriteLine($"[1, 2, 3, 5, 9] is [.., >= 3, _, _] = {result}");
// result is false, as first element is not greater than 1
result = fibonacci is [>1, .., 8];
Console.WriteLine($"[1, 2, 3, 5, 9] is [>1, .., 8] = {result}");