对于此错误,我该怎么办? [英] What do I need to do for this error?

查看:151
本文介绍了对于此错误,我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

       
    }

推荐答案

您确实需要更仔细地查看您的代码:
You really need to look more closely at your code:
public GetValue (double firstvalue, double secondvalue)


编译器期望推断什么返回类型?以及为什么名称以Get开头的方法没有返回值?


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?


问题在这里

The problem is here

public GetValue (double firstvalue, double secondvalue)



您可以通过提供可访问性(公用,专用),返回类型,函数名称来定义函数.您没有返回类型.如果该函数不返回任何内容,则使用void作为返回类型.



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)


要修复
中的错误更改
To fix the error change from
报价:

公共GetValue(双倍firstvalue,双倍secondsecondvalue)
{
MfirstValue = Math.Abs​​(firstvalue);
MsecondValue = Math.Abs​​(secondvalue);
}

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




to

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.


这篇关于对于此错误,我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆