'Calling a function in a class with the class as a parameter in c#

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?



Solution 1:[1]

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();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 qTzz