不是所有代码路径都返回值均值的意思,以及如何解决该问题 [英] what does not all code paths return a value mean and how do I fix it

查看:77
本文介绍了不是所有代码路径都返回值均值的意思,以及如何解决该问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

       公共字符串ReplaceTest()
        {
           字符串rep = this.textBox3.Text;
           字符串reped = rep.Replace("sir",rep);
        }

        public string ReplaceTest()
        {
            string rep = this.textBox3.Text;
            string reped = rep.Replace("sir", rep);
        }

我不理解

推荐答案

       公共字符串ReplaceTest()
        {
           字符串rep = this.textBox3.Text;
           字符串reped = rep.Replace("sir",rep);
        }

        public string ReplaceTest()
        {
            string rep = this.textBox3.Text;
            string reped = rep.Replace("sir", rep);
        }

我不明白

您已经声明了一个返回字符串的函数,但是您没有返回任何内容-这就是错误的含义.您如何修复它取决于您的意图.例如,您可以这样做:

You've declared a function that returns a string, but you haven't returned anything - that's what the error means.   How you fix it depends on what you intended.   For example, you might do:

public string ReplaceTest()
{
   string rep = this.textBox3.Text;
   string reped = rep.Replace("sir", rep);
   return reped;
}

如果您打算将修改后的字符串返回给此函数的调用者.

If your intention was to return the modified string to the caller of this function.

或者您也可以这样做:

public void ReplaceTest()
{
   string rep = this.textBox3.Text;
   string reped = rep.Replace("sir", rep);
}

如果您的目的是什么也不退货.

If your intention was to return nothing at all.


这篇关于不是所有代码路径都返回值均值的意思,以及如何解决该问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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