C# 8 新开关可以替换包含多个的代码块吗? :? : 表达?
Can C# 8 new switch replace a code block containing multiple ? : ? : expressions?
这是我现在正在做的一个例子:
return
shpc == 0 ? "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck." :
shpc == 1 ? "Currently, based on your selection below, you have one hidden card in your card deck." :
$"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible.";
代码字,但对添加到 switch 的内容了解不多我想知道是否也可以用 switch 表达式来完成?
试试这个
return shpc switch
{
0 => "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck.",
1 => "Currently, based on your selection below, you have one hidden card in your card deck.",
_ => $"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible."
};
肯定是:
return shpc switch
{
0 => "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck.",
1 => "Currently, based on your selection below, you have one hidden card in your card deck.",
_ => $"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible."
};
这是我现在正在做的一个例子:
return
shpc == 0 ? "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck." :
shpc == 1 ? "Currently, based on your selection below, you have one hidden card in your card deck." :
$"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible.";
代码字,但对添加到 switch 的内容了解不多我想知道是否也可以用 switch 表达式来完成?
试试这个
return shpc switch
{
0 => "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck.",
1 => "Currently, based on your selection below, you have one hidden card in your card deck.",
_ => $"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible."
};
肯定是:
return shpc switch
{
0 => "Currently, based on your selection below, you have not yet identified any hidden cards in your card deck.",
1 => "Currently, based on your selection below, you have one hidden card in your card deck.",
_ => $"Currently, based on your selection below, you have {shpc} hidden cards in your card deck. These will not be visible."
};