Is there any functional difference between these to function calls.
Method1:
public static void PrintMe(object obj)
{
Task task = new Task(() =>
{
Console.WriteLine(obj.ToString());
});
task.Start();
}
Method2:
public static void PrintMe(object obj)
{
Task task = new Task((object arg) =>
{
Console.WriteLine(arg.ToString());
}, obj);
task.Start();
}
The first one passes the variable obj to the task. The second one passes the value of obj.
To see the difference assign something else to obj after creating the task.
public static void PrintMe(object obj)
{
Task task = new Task(() =>
{
Console.WriteLine(obj.ToString());
});
obj = "Surprise";
task.Start();
}
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