Which of the below is a preferred coding style (in c# .net)
public void DoWork(Employee employee)
{
if(employee == null)
return;
if(!string.IsNullOrEmpty(employee.Name))
return;
// Do Work
}
or
public void DoWork(Employee employee)
{
if(employee != null && !string.IsNullOrEmpty(employee.Name))
{
// Do Work
}
}
0
When the first method fails it’s easy to see which part has the issue.
In the second approach you don’t know if it was the string being null or being empty that caused the return to happen.