Skip to content

Commit e6b4055

Browse files
committed
C#: Add list pattern sample file.
1 parent 98e125f commit e6b4055

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
3+
class ListPattern
4+
{
5+
public void M1(int[] x)
6+
{
7+
if (x is []) { }
8+
if (x is [1]) { }
9+
if (x is [_, 2]) { }
10+
if (x is [var y, 3, 4]) { }
11+
if (x is [5 or 6, _, 7]) { }
12+
if (x is [var a, .., 2]) { }
13+
if (x is [var b, .. { Length: 2 or 5 }, 2]) { }
14+
}
15+
16+
public void M2(string[] x)
17+
{
18+
switch (x)
19+
{
20+
case []:
21+
break;
22+
case ["A"]:
23+
break;
24+
case [_, "B"]:
25+
break;
26+
case [var y, "C", "D"]:
27+
break;
28+
case ["E" or "F", _, "G"]:
29+
break;
30+
case [var a, .., "H"]:
31+
break;
32+
case [var b, .. var c, "I"]:
33+
break;
34+
default:
35+
break;
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)