I often see in C# code the following convention:
some_type val;
val = something;
like
DataTable dt;
dt = some_function_returning_datatable();
or
DataTable dt = new DataTable();
dt = some_function_returning_datatable();
instead of
some_type val = something;
DataTable dt = some_function_returning_datatable();
I initially assumed that this was a habit left over from the days when you had to declare all local variables at the top of the scope. But I've learned not to dismiss so quickly the habits of veteran developers.
(In my 3rd code section will it not be wastage of memory when we assign dt
first with new
and then from function)
So, is there a good reason for declaring in one line, and assigning afterwards?