在使用位置模式匹配时,我本应使用".."(Slice)语法,就像它对数组元素所做的那样.
下面是我的例子:
// Create and populate a record
var vehicle = new VehicleData(2, "Model Y", 99_990M, 5, 3.5M);
// Record, deconstruct, and positional pattern matching
var bestForCustomer = vehicle switch
{
(_, "Model Y", ..) => "Best for small family", // Doesn't work
(_, "Model X", _, _, _) => "Best for large family", // _ does work
(_, "Model X Plaid", _, _, _) => "Best for performance",
_ => "Best for price"
};
有人知道为什么...(切片)语法在这种情况下不起作用?