如何从数据类型从字符串更改为var?
例:
private void button1_Click(object sender, EventArgs e)
{
work("checkBox1");
}
public void work(string check)
{
string number = "1";
if (number == "1")
{
check.Checked = true;
MessageBox.Show("True");
}
else
{
check.Checked = false;
MessageBox.Show("False");
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题
'string'不包含'Checked'的定义,也没有'Checked'接受的扩展方法
但我想工作按钮插入复选框名称
如何将值作为文本而不是void?
例:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = myvoid("foo", true);
//Error, Cannot imlicity convert type void to string
}
public void myvoid(string key , bool data)
{
if (data == true)
{
string a = key + " = true";
MessageBox.Show(a); //How to export this value to labe1.Text?
}
else
{
string a = key + " = false";
MessageBox.Show(a); //How to export this value to labe1.Text?
}
}
Run Code Online (Sandbox Code Playgroud)
如何从返回void的方法中指定值a,而不是显示消息框,并将其应用于label1.Text?