I have a general understanding of Lambda expressions but not sure what the () =>
syntax means. This code appears to return a list of Task items but I'm unsure how it executes or how to interpret what it means.
Can someone tell me:
() =>
mean?new Task
blocks are executed sequentially? private DateTime? _myTime = null;
private DateTime? _theirTime = null;
private bool _okToProcess = true;
List<Task> myTasks = new List<Task>
{
new Task( () =>
{
_myTime = GetMyTime();
}),
new Task( () =>
{
_theirTime = GetTheirTime();
_okToProcess = _myTime > _theirTime;
}),
new Task(() =>
{
if (_okToProcess)
{
WriteToMyLogStep("We are processing");
}
else
{
WriteToMyLogStep("We are NOT processing");
}
});
};
()
- represents the parameters taken by the anonymus method,
=>
- is generally read goes to and points to the anonymus methods body that uses those parameters (if any provided).
In your case the lamda expression is the same as:
delegate() { _myTime = GetMyTime(); }
As for the Tasks they are just added to a list, they are not executed. How they will be executed depends on how you want to execute them in the future. (maybe in a loop on the same thread or maybe on different threads).
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