Reputation: 1
class Fraction
{
public double Num { get; set; }
public double Denom { get; set; }
public void show(Fraction f)
{
Console.Write($"({f.Num}/{f.Denom})");
}
}
this bit of code shows no errors, but when I try to actually call the show(Fraction x) function it gives the "The name 'show' does not exist in the current context" error. I assume I can't set a class as a parameter, then what workaround could you suggest?
Upvotes: 0
Views: 151
Reputation: 126
This is the solution youre looking for
class Fraction
{
public double Num { get; set; }
public double Denom { get; set; }
public void show()
{
Console.Write($"({Num}/{Denom})");
}
}
You would call it this way.
var fraction = new Fraction{Num = 10, Denom = 10};
fraction.show();
Upvotes: 1