How to return the variable "string" from the "switch"?

python function return variable
return in python 3
how to use return value in another function python
python def return
python global variables
python return string
python function return list
python function without return

How to return the variable "string" from the "switch"?

There is a method

public string ParsingAll(int i, string cssSelector, string attr) 
{
  try
  {
    string str1 = "def";
    switch (i)
    {
      case 0: 
        var items = document.QuerySelectorAll(cssSelector); 

        str1 = items[0].TextContent.Trim();

        break;
    }
        return str1;
  }
  catch (Exception ex)
  {
    string s = ex.Message;    
  }
}

I get the error "not all branches of code return value"

How to return the variable "string" from the "switch"?

You are missing a return statement in catch block.

Generally, I would prefer a return null statement out of all try catch blocks to avoid these issues.

public string ParsingAll(int i, string cssSelector, string attr) 
{
  try
  {
    string str1 = "def";
    switch (i)
    {
      case 0: 
        var items = document.QuerySelectorAll(cssSelector); 

        str1 = items[0].TextContent.Trim();

        break;
    }
        return str1;
  }
  catch (Exception ex)
  {
    string s = ex.Message;    
    throw ;/// OR handle exception, log it, etc based on your requirements.
  }

  return null;
}

Function return values, After leaving the function f , the variable z and the parameters x and y will be The return value is immediately stored via unpacking into the variables lub and  A reference return value allows a method to return a reference to a variable, rather than a value, back to a caller. The caller can then choose to treat the returned variable as if it were returned by value or by reference. The caller can create a new variable that is itself a reference to the returned value, called a ref local.

Just add a return to your catch (or after it that would cover all branches by itself):

  catch (Exception ex)
  {
    string s = ex.Message;    
  }

return null;  

}

Python Tutorial: Functions, Functions shouldn't have to know what scope they're called from; the point of a function is to make a re-usable block of code that can be  Python functions can return multiple variables. These variables can be stored in variables directly. A function is not required to return a variable, it can return zero, one, two or more variables. This is a unique property of Python, other programming languages such as C++ or Java do not support this by default.

Your catch does not return anything, but the ParsingAll method requires you to return a string.

You could return null as suggested by @uɐʞɥsɐ or throw an exception:

catch (Exception ex)
{
    string s = ex.Message;
    throw;
}

How to use local variable in a function and return it?, These temporary variables are examples of local variables, pursued further in the next section. Notice something important here. The name of the variable we pass​  Local variables, as you've shown here, are just that, limited to the time they are locally alive in the function scope. In your example having a return type of int* and returning &i would have been equally incorrect.

6.2. Functions that Return Values, Python functions can return multiple variables. These variables can be stored in variables directly. A function is not required to return a variable, it can return zero​  The caller receives whatever data is stored in the variable. Expressions: Many developers use expressions as a shortcut. For example, you can simply return A + B rather than perform the calculation, place the result in a variable, and then return the variable to the caller. Using the expression is faster and accomplishes the same task.

Multiple return, For example, with that function, you can set a variable to the value that is returned using the following code (which would set result to 5). var result  After your newly created returnValue function, create a new variable named echo. Set the value of echo to be the results from calling the returnValue function. When you call the returnValue function, make sure to pass in any string you'd like for the parameter. I am unsure as to what is incorrect about the code I have written.

How to Return a Value in JavaScript, A return value can be any one of the four variable types: handle, integer, object, or string. The type of value your function returns depends largely on the task it  It is simple.just take a double variable for example double d=s.nextDouble (); then call all your methods with the argument d. Hope this will solve your problem.now you can accept my answer. – Android Killer Aug 6 '11 at 13:31

Comments
  • The catch block doesn't return anything
  • Possible duplicate of c# returning error "not all code paths return a value"
  • i'm amazed that you went all the way and copy pasted this guy's backwards name.
  • Lol. There you go, there's a link now.