Click here to Skip to main content
15,867,968 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Class, struct, or interface method must have a return type	


What I have tried:

public class MTMaths
    {
        private double _mfirstValue;
        public double MfirstValue
        {
          get { return _mfirstValue; }
          set { _mfirstValue = value; }
        }

        private double _msecondValue;
        public double MsecondValue
        {
          get { return _msecondValue; }
          set { _msecondValue = value; }
        }

        public GetValue (double firstvalue, double secondvalue)
        {
            MfirstValue = Math.Abs(firstvalue);
            MsecondValue = Math.Abs(secondvalue);
        }

        public double GetSum()
        {
            return (MfirstValue + MsecondValue);
        }

        public double GetSubtractValue()
        {
            return (mfirstValue - msecondValue);
        }

        public double GetMultipleValue()
        {
            return(mfirstValue * msecondValue);
        }

        public double GetDivisionValue()
        {
            return(mfirstValue / msecondValue);
        }

       
    }
Posted
Updated 22-Nov-17 23:59pm
Comments
Suvendu Shekhar Giri 23-Nov-17 6:02am    
You have forgotten to mention a return type in the function definition.
public void GetValue (double firstvalue, double secondvalue)

You really need to look more closely at your code:
C#
public GetValue (double firstvalue, double secondvalue)

What return type is the compiler expected to infer? And why is there no return with a value, on a method whose name begins with Get?
 
Share this answer
 
The problem is here

public GetValue (double firstvalue, double secondvalue)


you define a function by giving the accessibility (public, private), then the return type, then the function name. You don't have the return type. If the function doesn't return anything then use void as the return type.

public void GetValue (double firstvalue, double secondvalue)
 
Share this answer
 
To fix the error change from
Quote:
public GetValue (double firstvalue, double secondvalue)
{
MfirstValue = Math.Abs(firstvalue);
MsecondValue = Math.Abs(secondvalue);
}

to
C#
public void GetValue (double firstvalue, double secondvalue)
        {
            MfirstValue = Math.Abs(firstvalue);
            MsecondValue = Math.Abs(secondvalue);
        }


However, the method name doesn't look appropriate, to me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900