C#: Add list pattern sample file.

This commit is contained in:
Michael Nebel
2022-12-08 10:45:37 +01:00
parent 98e125fa98
commit e6b4055a5f

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
class ListPattern
{
public void M1(int[] x)
{
if (x is []) { }
if (x is [1]) { }
if (x is [_, 2]) { }
if (x is [var y, 3, 4]) { }
if (x is [5 or 6, _, 7]) { }
if (x is [var a, .., 2]) { }
if (x is [var b, .. { Length: 2 or 5 }, 2]) { }
}
public void M2(string[] x)
{
switch (x)
{
case []:
break;
case ["A"]:
break;
case [_, "B"]:
break;
case [var y, "C", "D"]:
break;
case ["E" or "F", _, "G"]:
break;
case [var a, .., "H"]:
break;
case [var b, .. var c, "I"]:
break;
default:
break;
}
}
}