Using the ValueTask of T object in C# 7.0
January 17, 2018 2 Comments
By now probably all .NET developers are aware of the await and async keywords, what they do and how they work.
Here’s a small example where the CalculateSum function simulates a potentially time-consuming mathematical operation:
public class AsyncValueTaskDemo
{
public void RunDemo()
{
int res = CalculateSum(0, 0).Result;
Console.WriteLine(res);
}
private async Task<int> CalculateSum(int a, int b)
{
if (a == 0 && b == 0)
{
return 0;
}
return await Task.Run(() => a + b);
}
}