Is it good practice use more that one RETURN statement in a method? [closed]

roypiggy

New Member
\[quote\] Possible Duplicate:
Why is it good practice to return at the end of a method \[/quote\]I would like to know if could be considered good practice use several RETURN statements in a method and why.If not, I would like to know how you would rewrite the code in a different way.\[code\]public string GetNominativeById(int? candidateId) { if (candidateId.HasValue) return repepositoryCandidate.GetById(candidateId.Value).Nominative; else return string.Empty; } }\[/code\]With one RETURN\[code\] public string GetNominativeById(int? candidateId) { string result; if (candidateId.HasValue) result = repepositoryCandidate.GetById(candidateId.Value).Nominative; else result = string.Empty; return result; } }\[/code\]
 
Back
Top