Created
February 10, 2015 18:18
-
-
Save ufcpp/5f11708effd4ca6e6d98 to your computer and use it in GitHub Desktop.
Splatting: tuple deconstruction for argument list
This file contains 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
(int sum, int count) Tally(IEnumerable<int> values) | |
{ | |
sum = 0; count = 0; | |
foreach (var value in values) { sum += value; count++; } | |
} | |
double Average(int sum, int count) => count == 0 ? 0 : sum / count; | |
var avg = Average(Tally(new[] { 1, 2, 3, 4, 5})); // タプル (int sum, int count) を分解して、Averabe(sum, count) に渡す |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment