【问题标题】:C# Ternary operator on WinForms CheckboxWinForms 复选框上的 C# 三元运算符
【发布时间】:2021-06-29 14:50:41
【问题描述】:

我正在尝试根据是否选中复选框来更改标签的文本?知道这里的三元运算符有什么问题吗?如果我使用“if else”,这将有效

enter image description here

private void chkBxCompress_CheckedChanged(object sender, EventArgs e)
{
    string encAndCom = "Encrypted and Compressed String";
    string encOnly = "Encrypted String";

    chkBxCompress.Checked ? outputLabelEnc.Text = encAndCom : outputLabelEnc.Text = encOnly;
     
}

【问题讨论】:

    标签: c# winforms conditional-operator


    【解决方案1】:

    改成

    outputLabelEnc.Text = chBxCompress.Checked ? encAndCom : encOnly;
    

    【讨论】:

    • 太棒了!谢谢!
    猜你喜欢
    • 2017-06-04
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 2015-04-04
    • 2015-05-15
    • 1970-01-01
    • 2014-01-16
    相关资源
    最近更新 更多