我有一个运行良好的代码:
var (msg, isCC, upd) = Settings.Mode switch
{
MO.Learn => ("Use this mode when you are first learning the phrases and their meanings.",
Settings.Cc == CC.H,
false),
MO.Practice => ("Use this mode to help you memorize the phrases and their meanings.",
Settings.Cc == CC.H,
false),
MO.Quiz => ("Use this mode to run a self marked test.",
Settings.Cc == CC.H,
true),
_ => ("", false, false)
};但在实际的应用程序中,我想将一个值返回到一个属性中,该属性在这里的多个位置被赋值:
string _modeMessage2;
public string ModeMessage2 { get => _modeMessage2; set => SetProperty(ref _modeMessage2, value); }尝试这样做不起作用:
var (this.ModeMessage2, isCC, upd) = Settings.Mode switch
{
MO.Learn => ("Use this mode when you are first learning the phrases and their meanings.",
Settings.Cc == CC.H,
false),
MO.Practice => ("Use this mode to help you memorize the phrases and their meanings.",
Settings.Cc == CC.H,
false),
MO.Quiz => ("Use this mode to run a self marked test.",
Settings.Cc == CC.H,
true),
_ => ("", false, false)
};有谁知道如何在不添加如下代码的情况下将值返回到ModeMesage2中?
ModeMessage2 = msg; 发布于 2019-11-24 06:37:07
如果左边的所有项都是字段或属性,那么它将起作用,如果您随后尝试将其中一项更改为类似var isCC的表达式,则会得到一个编译器错误,说明您不能混合表达式和声明。
因此,不幸的是,这不受支持。
https://stackoverflow.com/questions/59012331
复制相似问题