I found some code like this in a project I'm working on
public SqlDataReader SomeMethod(int someParam)
{
// ... some code goes here
SqlDataReader dataReader = m_command.ExecuteReader(CommandBehavior.CloseConnection);
return dataReader;
}
I was wondering what is better, the original or below
public SqlDataReader SomeMethod(int someParam)
{
// ... some code goes here
return m_command.ExecuteReader(CommandBehavior.CloseConnection);
}
Is there any advantage to creating the variable and then returning it as opposed to just returning the created reader? I would think no as it's just a reference. The example I give was what I found but it could be any variable type. One thing I can think of is during debugging, it's probably nice to look at what's in the variable.
Anybody like to contribute their 2 cents?