I have a method like below
public List<aspnet_Roles> GetAllRoles()
{
var rolesList = _dbProfile.aspnet_Roles.ToList();
return rolesList;
}
In this method first all the roles from database (LINQ to SQL) has been retrieved and assigned to a variable rolesList
of type var
.
I want to know if returning value directly is better instead of assigning it to other variables first and then returning it.
Is the below method is better than above version:
public List<aspnet_Roles> GetAllRoles()
{
return _dbProfile.aspnet_Roles.ToList();
}
Will the above two methods compile in IL as same or second version is better? Second version doesn't have the unnecessary variable declaration.
First method will help you with debugging. Right now, AFAIK, there is no way to watch return value of a method while debugging.
Other than that, there is no difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With