TimeSpan in C#
Durations that add, compare and scale like numbers.
var build = TimeSpan.FromSeconds(212);
var tests = TimeSpan.FromMinutes(3.5);
var total = build + tests;
Console.WriteLine(total);
Console.WriteLine(total.TotalMinutes);
// spans compare and scale like the durations they are
Console.WriteLine(build > tests);
Console.WriteLine(build * 2);
Console.WriteLine($"{build:mm\\:ss}");
How it works
FromSecondsandFromMinutesbuild spans readably.- Spans support
+,>and*directly. - The
mm\\:ssformat string prints a compact clock.
Keywords and builtins used here
var
The run, in numbers
- Lines
- 11
- Characters to type
- 329
- Tokens
- 69
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 44 seconds.
Step 2 of 3 in Dates & times, step 8 of 17 in The .NET library.