如何将例如 int 值绑定到下面的语句?
System::String^ Content = "just example";
int iAValue = 5;
lblOutput_{iValue}->Text = Content;
如何将例如 int 值绑定到下面的语句?
System::String^ Content = "just example";
int iAValue = 5;
lblOutput_{iValue}->Text = Content;
你没有;您使用某种数组或集合。初学者经常尝试这种事情。将程序逻辑与变量名称联系起来是不可能的,也不是一个好主意。
auto labels = gcnew List<Label>();
labels->Add(lblOutput1);
labels->Add(lblOutput2);
labels->Add(lblOutput3);
labels->Add(lblOutput4);
labels->Add(lblOutput5);
// ...
String^ Content = "just example";
int iAValue = 4;
labels[iAValue].Text = Content;
然后稍后您可以轻松地遍历所有这些:
for(int i = 0; i < labels->Count; ++i) {
// i is the label "number"
// labels[i] is the label
}