Support var declaration where type is inferred after the declaration. #7860
Answered
by
HaloFour
The-Futurist
asked this question in
Language Ideas
-
I was refactoring some code and now need to explicitly type a declaration after moving some code outside of a lambda, when I looked at it and wondered if this is feasible a language feature, the variable is named var start = DateTime.Now;
var filters = CreateFilters();
var objects;
Session.DownloadAdvancedDataSet(DatasetIdentifiers.Advanced.LEARNER_USAGE, filters, true, (data) =>
{
var stop = DateTime.Now;
var download_seconds = (stop - start).Seconds;
objects = ConvertStreamToRecords(data);
});
var table = InitializeDataTable(constring, objects);
using (var connection = CreateAndOpenDBConnection(constring))
{
TruncateTable(connection);
InsertTable(connection, table);
InsertNewHistory(connection, download_seconds, table);
} I want to simply declare Why is var restricted as it is today, are there perhaps cases (like this) where the inference can be reliably made? |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Jan 22, 2024
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
The-Futurist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: #6200 and #520