Last active
November 5, 2016 14:51
-
-
Save binki/d23857474627d6b3d9bb39cc40818114 to your computer and use it in GitHub Desktop.
#csharp7 #tuple #destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It took 00:00:01.0074966 to calculate hi. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Threading.Tasks; | |
namespace ValueTupleFun | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
(var result, var time) = TestTuple( | |
async () => | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(1)); | |
return "hi"; | |
}).Result; | |
Console.WriteLine($"It took {time} to calculate {result}."); | |
} | |
static async Task<(TResult result, TimeSpan time)> TestTuple<TResult>( | |
Func<Task<TResult>> actionAsync) | |
{ | |
var chronometer = Stopwatch.StartNew(); | |
return (await actionAsync(), chronometer.Elapsed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment