4

I have 3 methods.

1 method holding the value of 3000 1 method holding the value of 0.13

and I have created another method that I want to multiply these two figures together.

public override int FishPerTank()
{                
    return 3000;                
}

public override double WeightOut(double weightOut, double weightIn)
{
    return 0.13;
}

public override int HowMuchTheFishWeighOutKG()
{
    return (FishPerTank() * WeightOut());
}

I am receiving the syntax error on the WeightOut here:

public override int HowMuchTheFishWeighOutKG()
{
    return (FishPerTank() * WeightOut());
}
Omar
  • 16,329
  • 10
  • 48
  • 66
Simagen
  • 409
  • 2
  • 8
  • 18
  • @ClaudioRedi is correct. Also, watch that you are multiplying by a double (WeightOut), but then returning an integer. You'll lose the decimal places (not sure if that is your desired result). – Jason Down Jun 13 '12 at 17:21
  • Out of curiosity....why are you using override. Do these specific methods exist in some base class as virtual methods such that they need to be overridden with custom versions for your class? – Nevyn Jun 13 '12 at 17:22
  • 1
    @JasonDown - he won't get to the point of losing precision. He'll get a compile error because there is no implicit conversion from double to int. – hatchet - done with SOverflow Jun 13 '12 at 17:23
  • @hatchet: Yes you're right... the implicit conversion exists the other way around. Time for some coffee I think... – Jason Down Jun 13 '12 at 17:27

4 Answers4

13

WeightOut expect 2 parameters and you're not providing them

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
5

WeightOut(double weightOut, double weightIn) is declared with two parameters and you're calling it with none. Hence the error.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
5
WeightOut()  

expects two parameters. But why ? You don't use them.

Rewrite your method without the 2 parameters

public double WeightOut()
{
   return 0.13;
}
Jason Down
  • 21,731
  • 12
  • 83
  • 117
Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
  • I use the 2 parameters in my base class as it does the calculation there. – Simagen Jun 13 '12 at 17:22
  • In that case you had to use the two parameters, and when you call the method you have to pass them. Also, if you want to reuse the code of your base class you'll have to call it `base.WeightOut(parameter1, parameter2)`. – Gonzalo.- Jun 13 '12 at 17:25
3

You probably want to change

public override double WeightOut(double weightOut, double weightIn)
{
    return 0.13;
}

to

public override double WeightOut()
{
    return 0.13;
}

as you aren't using the parameters.

also why the override? May need to remove that if removing the parameters causes another syntax error, or fix it in the base class as well.

Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138