![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
c#中windowsapplication程序中新建的一个类应该放在哪 15
namespaceWindowsApplication2{publicpartialclassForm1:Form{publicForm1(){InitializeCom...
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
class Student
{
string No;
string Name;
string Sex;
string Hobby;
int Chinese;
int Math1;
int English;
int total;
public Student(string No, string Name, string Sex, string Hobby, int Chinese, int Math1, int English, int total)
{
this.No = No;
this.Name = Name;
this.Sex = Sex;
this.Hobby = Hobby;
this.Chinese = Chinese;
this.Math1 = Math1;
this.English = English;
this.total = total;
}
string setSex()
{
if (radioButton1.Checked) {
return "男";
}
}
}
像这样写的话,radioButton1.Checked没有提示出来,是我写进去的,运行之后就提示无法通过嵌套类型来访问外部类型的非静态成员 展开
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
class Student
{
string No;
string Name;
string Sex;
string Hobby;
int Chinese;
int Math1;
int English;
int total;
public Student(string No, string Name, string Sex, string Hobby, int Chinese, int Math1, int English, int total)
{
this.No = No;
this.Name = Name;
this.Sex = Sex;
this.Hobby = Hobby;
this.Chinese = Chinese;
this.Math1 = Math1;
this.English = English;
this.total = total;
}
string setSex()
{
if (radioButton1.Checked) {
return "男";
}
}
}
像这样写的话,radioButton1.Checked没有提示出来,是我写进去的,运行之后就提示无法通过嵌套类型来访问外部类型的非静态成员 展开
展开全部
你从一个类Form1中写了一个类Student,然后再在Student中调用Form1中的RadioButton控件,老兄,你的逻辑不是一点半点的混乱呀。Student要建在From1外边,在form1中添加你需要是事件。setSex方法加上参数,如string setSex(int sex),然后if(sex==1) return “男";在form1中的事件中取radioButton1的值,然后实例化Student,在调用setSex方法。我这么说你明白不?
追问
那个类的问题我懂了,但那个setSex方法不懂,setSex方法能直接用radioButton1.Checked吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询