2017-10-01 15 views
0

この課題ではメソッドの使用に問題があります。私の指示は次のとおりですメソッドを使用して変数を渡す際に問題が発生する#

セクションを取得するには、ScheduleStudentPresentationController(コントローラー)のインスタンスを含む変数を使用します。そのメソッドにstudentIdを渡す必要があります。上で定義したstudentId変数をパラメータとして使用します。

最後の行は、studentIdをパラメータとしてメソッドを呼び出し、それをセクションに割り当てる方法だと思いますが、明らかに正しくありません。

これはC#での初めてのプログラミングです。どんな方向性があっても、どのようにシンプルに見えるかは問題ありません。ここで

using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 

namespace A4_Skeleton 
{ 
    public partial class FormStudentSignUpForPresentationSlot : Form 
    { 
     private ScheduleStudentPresentationController controller; 
     private Section selectedSection; 

     public FormStudentSignUpForPresentationSlot() 
     { 
      InitializeComponent(); 


    //*********************************************************************** 
     // 1. 
     //Instantiate an instance of the ScheduleStudentPresentationController 
     // and assign it to the class variable named "controller" 
     //*********************************************************************** 
     controller = new ScheduleStudentPresentationController(); 


     } 

     private void buttonGetSection_Click(object sender, EventArgs e) 
     { 
      // Clear out any residual info 
      labelSectionInfo.Text = ""; 

      int studentId = 1; 


    //*********************************************************************** 
     // 2. 
     // Use the variable that contains an instance of 
     //ScheduleStudentPresentationController 
     // to get the section. You will need to pass that method a 
     //studentId. 
     // Use the studentId variable defined above as the parameter 
     //*********************************************************************** 

    Section section = controller(studentId); 

がScheduleStudentPresentationController

using System; 
using System.Collections.Generic; 

namespace A4_Skeleton 
{ 
    public class ScheduleStudentPresentationController 
    { 
     private PresentationSchedule presentationSchedule; 

     public ScheduleStudentPresentationController() 
     { 
      presentationSchedule = new PresentationSchedule(); 
     } 

     public Section getSection(int studentId) 
     { 
      SectionEnrolledStudent sectionEnrolledStudent = new 
      SectionEnrolledStudent(); 
      return sectionEnrolledStudent.getSection(studentId); 
     } 

     public Dictionary<DateTime, List<Slot>> getAvailableSlots(int 
     sectionId) 
     { 
      return presentationSchedule.getAvailableSlots(sectionId); 
     } 

     public bool selectSlot(int sectionId, int studentId, DateTime 
     slotDate, int slotNum) 
     { 
      return presentationSchedule.selectSlot(sectionId, studentId, 
      slotDate, slotNum); 
     } 
    } 
} 
+1

問題は何ですか? – stybl

+0

学生IDの整数を受け取り、セクションを返すScheduleStudentPresentationControllerで定義されたメソッドを呼び出す必要があります。 – Steve

+0

ScheduleStudentPresentationControllerを表示するように編集しました –

答えて

1

まずオフの定義である、あなたの割り当ては、明示的にScheduleStudentPresentationControllerを初期化し、コントローラと呼ばれるクラス変数に代入すると言います。したがって、それを示すにはthisキーワードを使用する必要があります。

Section section = controller(studentId); 

あなたはそれが法であるかのようにオブジェクトを「コール」しようとしているです:

public FormStudentSignUpForPresentationSlot() 
{ 
    InitializeComponent(); 
    this.controller = new ScheduleStudentPresentationController(); 
} 

さて、あなたはここで何をしているか、あなたの問題を、に関する。これはもちろん不可能です。おそらく、ScheduleStudentPresentationControllerにセクションを取得するための方法があります。私たちにそのクラスのコードを示すことなく、私はあなたに何をすべきかを正確に示すことができません。上記のコード行は、我々は現在のクラスのcontroller変数に格納されているScheduleStudentPresentationControllerクラスのインスタンスのgetSectionメソッドを呼び出します

Section section = this.controller.getSection(studentId); 

:しかし、それはのようなものになります。そのメソッドによって返された結果は、新しい変数sectionに格納されます。

+0

getSectionがメソッドであるという結論にどのようになったのか説明できますか?あなたは完全に正しいですが、どうやってそれを知っていましたか? –

+0

それはちょうどラッキーな推測でした:P。 'getSection'メソッドを呼び出すことは意味がありました。 – stybl

+1

あなたはキャメルケースの名前の使用を予測することさえできました... –

関連する問題