Reputation: 249
How do I reference the student object created in the first button in my method below? I thought I could simply do "ref object student" but when I do it won't let me use any of the methods associated with the student class and simply says "object does not contain a definition for . . ."
Button:
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();
}
}
Method:
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;
}
Upvotes: 0
Views: 58
Reputation:
You can use ref
ref Student student
Ref parameters are changed at the calling site. They are passed as references, not values. This means you can assign the parameter in the called method and have it also be assigned at the calling site.
Upvotes: 0