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没有提示出来,是我写进去的,运行之后就提示无法通过嵌套类型来访问外部类型的非静态成员
展开
 我来答
迈讯科智能技术
2013-10-23 · TA获得超过265个赞
知道小有建树答主
回答量:305
采纳率:0%
帮助的人:160万
展开全部
你从一个类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吗
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qinwei0406
2013-10-24 · TA获得超过197个赞
知道小有建树答主
回答量:118
采纳率:0%
帮助的人:57万
展开全部
radioButton1.Checked应该是个界面checkBox控件,当被选中时,返回性别为男
string a=string.Empty;
a=setSex();
当界面勾选了这个checkBox时,获得返回值“男”,这段代码应该放到控件的触发时间中。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式