I am trying to refactor some code by extracting methods. I need to separate the (simplified) code below into sub methods for each region, but I get the error "When the selection contains a return statement, all code paths must be terminated by a return statement too".
try
{
#region one
if (order == "1")
{
...do something
return result;
}
#endregion
#region two
if (order == "2")
{
...do something
return result;
}
#endregion
}
catch (Exception ex)
{
...exception handle
}
return result;
How should this be done?
You need to extract the body of each
if
statement into its own method. You cannot extract the entireif
statement into a method, for exactly the reason the error message you're getting is telling you.