var x = new int[] { 1, 2 };
var y = x switch {
{ 1, 2 } => "yea",
_ => "nay"
};
fails to compile.
How can I pattern-match arrays?
You have to expand the elements of the array yourself like so
var x = new int[] { 1, 2 };
var y = (x[0], x[1]) switch {
(1, 2) => "yea",
_ => "nay"
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With