Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created October 28, 2017 12:26
Show Gist options
  • Save Ibro/0d3db622d6d7b0e651a9fbe96d61baa0 to your computer and use it in GitHub Desktop.
Save Ibro/0d3db622d6d7b0e651a9fbe96d61baa0 to your computer and use it in GitHub Desktop.
Tuples in C# 7
List<int> numbers = new List<int> { 3, 5, 11, 4, 7 };
var result = GetLowestHighest(numbers);
Console.WriteLine(result.Item1); // ugly?
Console.WriteLine(result.Item2); // yeah, ugly..
// Notice the return type of the method. It's tuple
private static(int, int) GetLowestHighest(IReadOnlyCollection < int > numbers) {
int lowest = numbers.Min(n => n);
int highest = numbers.Max(n => n);
return (lowest, highest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment