日期:2014-05-18 浏览次数:20741 次
private void button1_Click(object sender, EventArgs e) { StudentInfo i; StudentSearch j = new StudentSearch(); i = j.Search2(textBox1.Text,checkBox1.Checked); MessageBox.Show("查询到的学生信息是:" + "\n" + i.name + "\n" + i.sex + "\n" + i.year + "\n" + i.zhuanye+ "\n" ); }
class StudentSearch { public string abc { get { return "请输入查询条件"; } } public StudentInfo Search2(string si,bool d) { StudentInfo k = new StudentInfo(); if (d) { if (si == "") { return abc; } else if (si == "S001") { k.name = "Tom"; k.sex = "男"; k.year = 201008; k.zhuanye = "计算机科学与技术"; } } else if (si == "S001") { k.name = "Tom"; k.sex = "男"; k.year = 201008; k.zhuanye = "计算机科学与技术"; } return k; } } }
--不是定义返回的是StudentInfo吗,怎么返回个字符串出来,不错才怪 if (si == "") { return abc; }