gpt4 book ai didi

c# - C# 8 新 switch 可以替换包含多个的代码块吗? : ? : expressions?

转载 作者:行者123 更新时间:2023-12-02 15:49:50 25 4
gpt4 key购买 nike

这是我现在正在做的一个示例:

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."
};

关于c# - C# 8 新 switch 可以替换包含多个的代码块吗? : ? : expressions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59510149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com