C#自我程式複習
基本的資料介面輸入與輸出資料。
主程式:
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(namebox.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text))
{
MessageBox.Show("請再次確認資料");
}
else
{
Student_data A1 = new Student_data(namebox.Text, (int)numericUpDown1.Value, (int)numericUpDown2.Value, (int)numericUpDown3.Value, (int)numericUpDown4.Value,
(int)numericUpDown6.Value, (int)numericUpDown5.Value, Int32.Parse(textBox2.Text), Int32.Parse(textBox3.Text), Int32.Parse(textBox4.Text));
MessageBox.Show(A1.result(), "成績查詢");
}
}
private void button2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(namebox.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text))
{
MessageBox.Show("請再次確認資料");
}
else
{
Student_data A1 = new Student_data(namebox.Text, (int)numericUpDown1.Value, (int)numericUpDown2.Value, (int)numericUpDown3.Value, (int)numericUpDown4.Value,
(int)numericUpDown6.Value, (int)numericUpDown5.Value, Int32.Parse(textBox2.Text), Int32.Parse(textBox3.Text), Int32.Parse(textBox4.Text));
MessageBox.Show(A1.student_basic_data(), "學生基本資料");
}
}
物件程式:
class Student_data
{
//property
public int grade, classes, id, yy, mm, dd, ch, en, math;
public string name;
public Student_data(string name,int grade,int classes,int id,int yy,int mm,int dd,int ch,int en,int math)
{
this.name = name;
this.grade = grade;
this.classes = classes;
this.id = id;
this.yy = yy;
this.mm = mm;
this.dd = dd;
this.ch = ch;
this.en = en;
this.math = math;
}
//method
public string student_basic_data()
{
return "姓名:" + name + "\r\n班級:" + grade + "年" + classes + "班" + id + "號\r\n出生:" + yy + "年" + mm + "月" + dd + "日";
}
public string result()
{
return "姓名:" + name + "\r\n班級:" + grade + "年" + classes + "班" + id + "號\r\n" +
"成績\r\n國文:" + ch + "\r\n英文:" + en + "\r\n數學:" + math ;
}
}
主程式:
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(namebox.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text))
{
MessageBox.Show("請再次確認資料");
}
else
{
Student_data A1 = new Student_data(namebox.Text, (int)numericUpDown1.Value, (int)numericUpDown2.Value, (int)numericUpDown3.Value, (int)numericUpDown4.Value,
(int)numericUpDown6.Value, (int)numericUpDown5.Value, Int32.Parse(textBox2.Text), Int32.Parse(textBox3.Text), Int32.Parse(textBox4.Text));
MessageBox.Show(A1.result(), "成績查詢");
}
}
private void button2_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(namebox.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text))
{
MessageBox.Show("請再次確認資料");
}
else
{
Student_data A1 = new Student_data(namebox.Text, (int)numericUpDown1.Value, (int)numericUpDown2.Value, (int)numericUpDown3.Value, (int)numericUpDown4.Value,
(int)numericUpDown6.Value, (int)numericUpDown5.Value, Int32.Parse(textBox2.Text), Int32.Parse(textBox3.Text), Int32.Parse(textBox4.Text));
MessageBox.Show(A1.student_basic_data(), "學生基本資料");
}
}
物件程式:
class Student_data
{
//property
public int grade, classes, id, yy, mm, dd, ch, en, math;
public string name;
public Student_data(string name,int grade,int classes,int id,int yy,int mm,int dd,int ch,int en,int math)
{
this.name = name;
this.grade = grade;
this.classes = classes;
this.id = id;
this.yy = yy;
this.mm = mm;
this.dd = dd;
this.ch = ch;
this.en = en;
this.math = math;
}
//method
public string student_basic_data()
{
return "姓名:" + name + "\r\n班級:" + grade + "年" + classes + "班" + id + "號\r\n出生:" + yy + "年" + mm + "月" + dd + "日";
}
public string result()
{
return "姓名:" + name + "\r\n班級:" + grade + "年" + classes + "班" + id + "號\r\n" +
"成績\r\n國文:" + ch + "\r\n英文:" + en + "\r\n數學:" + math ;
}
}
留言
張貼留言