多个return和一个return

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

 

你可能感兴趣的:(多个return和一个return)