for (int i = 1; i < 5; i++) { var name = "radioButton" + i; string n = this.Controls[name].Tag.ToString(); if (n == "Number") { MessageBox.Show("1111"); } 这句为什么报错“System.NullReferenceException”类型的未经处理的异常?
我手动给tag赋值了 但是string n 的值还是null[/quote]
首先呢?你刪除所有radioButton,然後就保留radioButton1,然後賦值radioButton1的Tag值,然後
for (int i = 1; i <2; i++)
這樣子能不能成功[/quote]
这样可以 这是什么原理?[/quote]
判斷一下NULL值啊
for (int i = 1; i < 5; i++)
{
var name = "radioButton" + i;
if (this.Controls[name] != null)
{
if (this.Controls[name].Tag != null)
{
string n = this.Controls[name].Tag.ToString();
if (n == "Number")
{
MessageBox.Show("1111");
}
}
}
我手动给tag赋值了 但是string n 的值还是null[/quote]
首先呢?你刪除所有radioButton,然後就保留radioButton1,然後賦值radioButton1的Tag值,然後
for (int i = 1; i <2; i++)
這樣子能不能成功[/quote]
这样可以 这是什么原理?