Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created October 28, 2017 12:27
Show Gist options
  • Save Ibro/5d5df83c9f0255b60ae56dab4b908d35 to your computer and use it in GitHub Desktop.
Save Ibro/5d5df83c9f0255b60ae56dab4b908d35 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 someTupleResult = GetSomeTuple(numbers);
// This is much better!
Console.WriteLine(someTupleResult.highest);
Console.WriteLine(someTupleResult.lowest);
Console.WriteLine(someTupleResult.LuckyName);
// tuple with 3 params and named return parameters
private static(int lowest, int highest, string LuckyName) GetSomeTuple(IReadOnlyCollection < int > numbers) {
int lowest = numbers.Min(n => n);
int highest = numbers.Max(n => n);
return (lowest, highest, "Johnny Boy");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment