如何在下面的方法中引用第一个按钮中创建的学生对象?我以为我可以简单地做“ref object student”,但是当我这样做时,不会让我使用与学生类相关的任何方法,而只是说“对象不包含...的定义”。
按钮:
private void addStudentButton_Click(object sender, EventArgs e) //Add Student Button
{
string name = nameBox.Text;
string course = courseBox.Text;
bool NumTrue = true;
decimal asgnScore;
decimal mScore;
decimal fScore;
decimal itMJR; //IT Major Check
student = new Student(name);
student.SetCourse(course);
VerifyNums(ref NumTrue, out asgnScore, out mScore, out fScore);
if (NumTrue)
{
student.Assignment = asgnScore;
student.Midterm = mScore;
student.final = fScore;
AddPoints(out itMJR);
clearButton_Click(sender, e);
}
else
{
BadInput();
}
}
方法:
private void CalculateGrades(ref object student, out decimal averageExamScore, out decimal percentGrade, ref decimal AW, ref decimal TW, ref decimal itMJR)
{
asgnScore = ((asgnScore + itMJR) * AW);
name = nameBox.Text; course = courseBox.Text;
averageExamScore = (((fScore + itMJR) + (mScore + itMJR)) / 2);
averageExamScore = averageExamScore * TW;
percentGrade = averageExamScore + asgnScore;
}
答案 0 :(得分:1)
使用此代替ref object student
:
ref Student student
答案 1 :(得分:0)