多個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"; } } }
相關文章
相關標籤/搜索