//一个return
namespace CleanCSharp.Methods.Dirty
{
class MethodExitPoints
{
public string GenerateAgeAppropriateGreeting(
int customerAgeInYears)
{
string greeting;
if (customerAgeInYears < )
{
greeting = "Yo!";
}
else if (customerAgeInYears < )
{
greeting = "Hi there";
}
else
{
greeting = "Dear Sir/Madam";
}
return greeting;
}
}
}
//多个return
namespace CleanCSharp.Methods.Clean
{
class MethodExitPoints
{
public string GenerateAgeAppropriateGreeting(
int customerAgeInYears)
{
if (customerAgeInYears < )
{
return "Yo!";
}
if (customerAgeInYears < )
{
return "Hi there";
}
return "Dear Sir/Madam";
}
}
}