Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在for循环中创建定义数量的标签_C#_Wpf_Visual Studio 2010_Dynamic_Label - Fatal编程技术网

C# 在for循环中创建定义数量的标签

C# 在for循环中创建定义数量的标签,c#,wpf,visual-studio-2010,dynamic,label,C#,Wpf,Visual Studio 2010,Dynamic,Label,我想在for循环中动态创建10个标签 string labelName; for(int i = 0; i < 10; i++) { labeName = "Label" & i; // Creata & Instanciate the label here, How ? } 字符串标签名; 对于(int i=0;i

我想在for循环中动态创建10个标签

string labelName;

for(int i = 0; i < 10; i++)
{
    labeName = "Label" & i;
    // Creata & Instanciate the label here, How ?
}
字符串标签名;
对于(int i=0;i<10;i++)
{
labeName=“Label”&i;
//如何在此处创建并实例化标签?
}

如何创建一组不是UI元素的对象?使用集合:

List<Label> labels = new List<Label>();
for (int i = 0; i < 10; i++)
{
    Label label = new Label();
    // Set properties here
    labels.Add(label);
}
列表标签=新列表();
对于(int i=0;i<10;i++)
{
标签=新标签();
//在此处设置属性
标签。添加(标签);
}
您可能希望将这些标签添加到表单、页面或其他任何地方…

List labelName=new List();
List<string> labelName = new List<string>();    
for(int i = 0; i < 10; i++)
{
    labeName.Add(string.Concat("Label", i));
}
对于(int i=0;i<10;i++) { Add(string.Concat(“Label”,i)); }