它是Windows窗体中心智游戏的部分代码。我的问题是为什么我要将tableLayoutPanel1.Controls的“Label”设置为局部变量标签?另外为什么它被放入if条件?
Label label;
int randomNumber;
for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++)
{
if (tableLayoutPanel1.Controls[i] is Label)
label = (Label)tableLayoutPanel1.Controls[i];
else
continue;
}
简短的回答:qazxsw poi是qazxsw poi和qazxsw poi与qazxsw poi让它安全。
更长的答案:这里是你的代码片段的注释和清理版本(删除了不必要的(Label)
变量和explicit type conversion-branch:
if
该片段的结果是label变量引用tableLayoutPanel1.Controls-collection中的最后一项,其类型与Label兼容。