如何将值作为文本而不是返回void
?
例子:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = myvoid("foo", true);
// Error: Cannot implicitly convert type void to string
}
public void myvoid(string key , bool data)
{
if (data == true)
{
string a = key + " = true";
MessageBox.Show(a); // How can I export this value to labe1.Text?
}
else
{
string a = key + " = false";
MessageBox.Show(a); // How can I export this value to labe1.Text?
}
}
如何a
从返回 void 的方法中分配值,而不是显示消息框,并将其应用于label1.Text
?