none
what does not all code paths return a value mean and how do I fix it

    Question

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

    i dont understand

    Tuesday, March 28, 2017 3:57 PM

All replies

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

    i dont understand

    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.

    Or you might instead do:

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

    If your intention was to return nothing at all.


    -cd Mark the best replies as answers!

    Tuesday, March 28, 2017 4:02 PM
    Moderator
  • In this case, it means you declared the function as returning a string, but are not actually returning anything.

    You need a return statement:

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

    Tuesday, March 28, 2017 4:03 PM
  • thank you
    Tuesday, March 28, 2017 4:11 PM