Skip to content

Instantly share code, notes, and snippets.

@Ibro Ibro/Tuples.cs
Created Oct 28, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.