【发布时间】:2016-03-27 17:58:57
【问题描述】:
int j = 1;
label+j.Text = "";
变量名标签后显示错误
Error 1 The name 'label' does not exist in the current context
如何在 C# 中使用它?
【问题讨论】:
int j = 1;
label+j.Text = "";
变量名标签后显示错误
Error 1 The name 'label' does not exist in the current context
如何在 C# 中使用它?
【问题讨论】:
使用Find 方法,您可以在运行时通过其名称获得任何控制:
Label lbl = this.Controls.Find("label"+j, true).FirstOrDefault() as Label;
lbl.text = "";
它返回所有可能控件的集合,但我们只需要一个(第一个),如果它的名称是唯一的。
【讨论】:
如果您的控件名称是label,那么您可能想要这样做
this.label.Text = string.Empty;
【讨论】: