0
private void btnset_Click(object sender, RoutedEventArgs e)
{
    Student newstudent = new Student();
    {
        newstudent.Forename = txtforename.Text;
        newstudent.Surname = txtsurname.Text;
        newstudent.Course = txtcourse.Text;
        newstudent.DoB = txtdob.Text;
        newstudent.Matriculation =int.Parse(txtmatric.Text);
        newstudent.YearM = int.Parse(txtyearm.Text);
    }
}

オブジェクトからデータを取得しようとしています。現在作成しているプログラムには、現在 3 つのボタンが含まれています。

  1. set(テキスト ボックスにデータを設定し、新しい を作成しますStudent)
  2. clear(言及されたテキストボックスをクリアします)
  3. get.

からgetデータを取得する必要があり、newstudentその方法がよくわかりません。

編集:学生は、このデータを作成している別のクラスであることも追加する必要があります

4

3 に答える 3

0

Studentクラスで、次のように、データを保持する変数を宣言します。

Student theStudent;

「set」メソッドでのnewing up はStudent、オブジェクトのデータの作成と保存を処理しStudentます。

theStudent「取得」ボタンのクリック ハンドラで、次のように の値を取得できます。

private void btnget_Click(object sender, RoutedEventArgs e)
{
    txtforename.Text = theStudent.Forename;
    txtsurname.Text = theStudent.Surname;
    txtcourse.Text = theStudent.Course;
}
于 2013-10-08T20:59:31.450 に答える