Stefan N
Stefan N

Reputation: 73

I am trying to calculate side C of a triangle using pythagoras, using a class.. C#

This is the last assignment of my C# course.. In this assignment i program using a class. I can make this all work without use of a class, but can not (thusfar) with.

here is the code:

public class Pyt
{
    private double _Rh1;
    private double _Rh2;

    public Pyt (double rh1, double rh2)
    {
      _Rh1 = rh1;
      _Rh2 = rh2;
     }

    public double _Som()
    {
      return _Rh1 * _Rh1 + _Rh2 * _Rh2;
    }

    public double _Som2()
    {
      return Math.Sqrt(_Som);///here is where the problems arise.. at the last
     }
       /// calculation.. it gives error, can not convert from 
       ///method group to double.
 }

as you might have read, it gives error can not convert from method group to double.

I have thus far tried several things, my method seems ok (using 2 sum variables)

Can anybody help?

greetings,

Stefan

Upvotes: 1

Views: 131

Answers (2)

Batesias
Batesias

Reputation: 2146

_Som is just the function. You want to caculate the square root on the result of the function. To do that you need to invoke the function using the parenthesis.

public double _Som2()
{
    return Math.Sqrt(_Som());
}

Upvotes: 1

The Photon
The Photon

Reputation: 1367

In your code, _Som is a function for calculating the sum of squares of the two sides. You can't take the square root of a function.

You have to use the function by calling it, and take the square root of the result that the function returns.

Upvotes: 0

Related Questions