Created
October 28, 2017 12:26
-
-
Save Ibro/0d3db622d6d7b0e651a9fbe96d61baa0 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 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