Created
October 28, 2017 12:27
-
-
Save Ibro/5d5df83c9f0255b60ae56dab4b908d35 to your computer and use it in GitHub Desktop.
Tuples in C# 7
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
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