I want to know what is considered better way of returning when I have if
statement.
Example 1:
public bool MyFunction()
{
// Get some string for this example
string myString = GetString();
if (myString == null)
{
return false;
}
else
{
myString = "Name " + myString;
// Do something more here...
return true;
}
}
Example 2:
public bool MyFunction()
{
// Get some string for this example
string myString = GetString();
if (myString == null)
{
return false;
}
myString = "Name " + myString;
// Do something more here...
return true;
}
As you can see in both examples function will return true/false
but is it a good idea to put else
statement like in first example or it is better to not put it?
else
.