不是所有代码路径都返回值均值的意思,以及如何解决该问题 [英] what does not all code paths return a value mean and how do I fix it
问题描述
公共字符串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屋!