C# 如何在c语言中连接变量#

C# 如何在c语言中连接变量#,c#,variables,concatenation,C#,Variables,Concatenation,我一直在四处寻找,但没有看到我在寻找什么。 我试着用一个变量填充单选按钮描述 for (int i = 1; i <= 7; i++) { ctrl = "radiobutton" + i; ctrl.Content = "[somevalue]"; // fill each of the radiobuttons descriptions } for(int i=1;i您可以将每个单选按钮的标记属性指定给一些对您有意义的值。 根据这些值从父控件的控件集合中拾取它们。非常简单;使

我一直在四处寻找,但没有看到我在寻找什么。 我试着用一个变量填充单选按钮描述

for (int i = 1; i <= 7; i++)
{
  ctrl = "radiobutton" + i;
  ctrl.Content = "[somevalue]"; // fill each of the radiobuttons descriptions
}

for(int i=1;i您可以将每个
单选按钮的
标记
属性指定给一些对您有意义的值。

根据这些值从父控件的
控件
集合中拾取它们。

非常简单;使用
表单.FindControl
()


免责声明:我从未说过你应该这样做。那种设计(和命名方案)很糟糕;但你会这样做。

谢谢大家,我想到了这个:

int items = count / 2;
string[] ctrl= new string[items];
RadioButton [] radioButtons = new RadioButton[items];
for (int i = 0; i < items; i++)
{
    radioButtons[i] = new RadioButton();
    radioButtons[i].Content = EffectsArray[i];
    stackPanelEffRadio.Children.Add(radioButtons[i]);
}
int items=count/2;
字符串[]ctrl=新字符串[项目];
RadioButton[]radioButtons=新的RadioButton[项目];
对于(int i=0;i

适用于我!

如果您将单选按钮创建为数组,您可以遍历数组并根据需要分配内容。您应该研究控件的数据绑定,而不是创建大量样板代码来为控件分配值。您看过带绑定的radiobuttonlist了吗?我将更深入地研究数据绑定谢谢!!
int items = count / 2;
string[] ctrl= new string[items];
RadioButton [] radioButtons = new RadioButton[items];
for (int i = 0; i < items; i++)
{
    radioButtons[i] = new RadioButton();
    radioButtons[i].Content = EffectsArray[i];
    stackPanelEffRadio.Children.Add(radioButtons[i]);
}