We know about the deferred execution or lazy evaluation features introduced in C#. But at times, people become confused with them. Because there is no significant difference. You can only know if you know the internals. Shouldn't there be a syntactical difference between them to remove confusion?
I think the keyword
let of F# can be imported to C# to specify the lazy evaluations. Like-
let selectedItems = Items.Where(i => i.Count < 5);
What do you guys think?
In reply to the first answer, I am not proposing that the
let keyword is to be used in the places where the lazy evaluation is already happening according to the present compiling model. Then it will be of no use actually. I am proposing that the
let keyword should define the type of execution. To be clear-
var selectedItems = Items.Where(i => i.Count < 5).ToList();
will be executed eagerly by present model. But my proposal is, if we use
let selectedItems = Items.Where(i => i.Count < 5).ToList();
it will be executed later, just when required. Though this is not desirable as it will return different lists of same items each time. The 'thing' defined with
let keyword can be thought of a constant 'expression' like F#.
Linking this SO answer as a proof of people's annoyance with deferred execution-