Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created February 10, 2015 18:18
Show Gist options
  • Save ufcpp/5f11708effd4ca6e6d98 to your computer and use it in GitHub Desktop.
Save ufcpp/5f11708effd4ca6e6d98 to your computer and use it in GitHub Desktop.
Splatting: tuple deconstruction for argument list
(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