我有以下开关表达式:
public Size GetSize(string brand, string isGift) => (brand, isGift) switch
{
(brand: "1", isGift: "Y") => Size.Small,
(brand: "1", isGift: "N") => Size.Medium,
(brand: "2") => Size.Big, // in this line I get and error
_ => Size.NoSize
};所以,我知道如果商标是"2“,它将总是Size.Big,我想忽略这条语句中的isGift字符串,但我得到了一个编译错误。有没有办法解决这个问题?
发布于 2021-07-23 00:35:31
您可以只使用下划线:
public Size GetSize(string brand, string isGift) => (brand, isGift) switch
{
(brand: "1", isGift: "Y") => Size.Small,
(brand: "1", isGift: "N") => Size.Medium,
(brand: "2", _) => Size.Big,
_ => Size.NoSize
};https://stackoverflow.com/questions/68488489
复制相似问题