There are numerous problems with this code but they might not be what you think they are.
First off, Public is wrong; C# requires public.
Second, the use of the local Mgrade is strange and unnecessary, but interestingly enough not actually wrong; it is legal to do an assignment and a return in one step like that. But in this case you do not need to; just return 'A'; without the local assignment.
Third, the method is misnamed because it does not set the Grade property. If you intend it to set the grade then it should be void returning:
public void SetGrade(float score)
{
if(score >= 90.0)
{
this.grade = 'A';
}
this.grade = 'F';
}
If instead the method is intended to be a conversion from floats to chars then it should be static:
public static char ScoreToGrade(float score)
{
if(score >= 90.0)
{
return 'A';
}
return 'F';
}
Frankly, I'd be inclined to do both:
public void SetGrade(float score)
{
this.grade = ScoreToGrade(score);
}
There, now you've got the best of both worlds.
Fourth, this is just a stylistic point; you might consider:
public char Grade { get; private set; }
the compiler will generate an "invisible" backing field for you, so you don't have to manage it yourself. This syntax means that Grade can be read from anywhere and written to from within this class.
Mgradeand why are you trying to assign to it? And why does yourGradeproperty have a capitalPin the access modifier? (C# is case-sensitive.)AorF- or do you want to return "A", "B", "C", "D", "E" or "F" depending ongrade?