日期:2014-05-18  浏览次数:20790 次

构造函数
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace teacher
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {
  student a1 = new student();
  a1._name = textBox1.Text;
  a1._sex = textBox2.Text;
  a1._age = textBox3.Text;
  a1.show("a");
  }

  private void button2_Click(object sender, EventArgs e)
  {
  student a1 = new student();
  a1._name = textBox1.Text;
  a1._sex = textBox2.Text;
  a1._age = textBox3.Text;
  a1.show(1);
  }

  private void button4_Click(object sender, EventArgs e)
  {
  student a1 = new student();
  a1._name = textBox1.Text;
  a1._sex = textBox2.Text;
  a1._age = textBox3.Text;
  a1.show('a');
  }

  private void button3_Click(object sender, EventArgs e)
  {
  student a1 = new student();
  a1._name = textBox1.Text;
  a1._sex = textBox2.Text;
  a1._age = textBox3.Text;
  a1.show(1.11);
  }

  }
  public class student
  {
  #region zhiduan
  //一对#region,#endregion可以管理一组代码
  //字段成员
  private string name;
  private string sex;
  private int age;
  #endregion
  #region shuxing
  //属性
  public string _name
  {
  get
  {
  return _name;
  }
  set
  {
  _name = name;
  }
  }
  public string _sex
  {
  get { return _sex; }
  set { _sex = value;}
  }
  public string _age
  {
  get { return _age;}
  set { _age = value;}
  }
  #endregion
  #region fangfa
  //方法
  public void show(string yuwen)
  {
  MessageBox.Show(name+","+sex+","+age+","+"喜欢的科目"+yuwen);
  }
  public void show(int shuxue)
  {
  MessageBox.Show(name + "," + sex + "," + age + "," + "喜欢的科目" + shuxue);
  }
  public void show(char yinyu)
  {
  MessageBox.Show(name + "," + sex + "," + age + "," + "喜欢的科目" + yinyu);
  }
  public void show(double huaxue)
  {
  MessageBox.Show(name + "," + sex + "," + age + "," + "喜欢的科目" + huaxue);
  }
  #endregion
  }
}



问题是:
set
{
  _name=val