首页 > 代码库 > 多个return和一个return

多个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