C# 在C中传递单选按钮和标签作为参数#

C# 在C中传递单选按钮和标签作为参数#,c#,reference,radio-button,label,C#,Reference,Radio Button,Label,使用Microsoft Visual Studio。 我有一个带有单选按钮和标签的表单,如何将其中一个指定给对象? 我有一门课,像: 职业玩家 { 私有字符串名称; private System.Windows.Forms.RadioButton myRadioButton; private System.Windows.Forms.Label myLabel; 公共播放器(字符串名称,System.Windows.Forms.RadioButton MyRadioButton,System.W

使用Microsoft Visual Studio。 我有一个带有单选按钮和标签的表单,如何将其中一个指定给对象? 我有一门课,像:

职业玩家
{
私有字符串名称;
private System.Windows.Forms.RadioButton myRadioButton;
private System.Windows.Forms.Label myLabel;
公共播放器(字符串名称,System.Windows.Forms.RadioButton MyRadioButton,System.Windows.Forms.Label MyLabel)
{
this.name=名称;
this.myRadioButton=myRadioButton;
this.myLabel=myLabel;
}
}
我以主要形式这样做,但这是错误的:

使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
名称空间myprogram
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
玩家=
{
新玩家(“迈克”,RadioButton1,label1),
新玩家(“鲍勃”,RadioButton2,label2)
};
错误是

字段初始值设定项不能引用字段、方法或属性 静态“myprogram.Form1.RadioButton1”


将公众置于职业玩家之前:

public class Player
{
  private string _name;
  private System.Windows.Forms.RadioButton _myRadioButton;
  private System.Windows.Forms.Label _myLabel;
  public Player(string name, System.Windows.Forms.RadioButton myRadioButton, 
                             System.Windows.Forms.Label myLabel)
  {
    _name = name;
    _myRadioButton = myRadioButton;
    _myLabel = myLabel;
  }
}
以及:


你在哪里编写了初始化数组播放器的代码?你能为你的问题添加更多的上下文吗?你确定
RadioButton1
RadioButton2
是readio按钮的实例吗?更新你的问题并提供完整的代码。是的,不要在注释中编写代码。除非只有一行代码,否则它是无法理解的。哦,是的,它必须在Form1_Load()内
private void Form1_Load(object sender, EventArgs e)
    {


//Assuming that you have added two radio buttons and two labels to the form      
//from designer, then the default generated name for the control is     
//radiobutton1 not Radiobutton1 and so on

    Player[] players =
    {
        new Player ("Mike", radioButton1, label1),
        new Player("Bob", radioButton2, label2)
    };
}