Background
I'm implement a data structure which is used to convert a time range to human-readable text, e.g. 0-7 days to "Within 1 Week", 7-30 days to "1 Week to 1 Month". Here I use Tuple<int,int> to represent the time range but not two integers, because we can define a Dictionary<Tuple<int, int>, String> to represent a map from time range to text.
1 2 3 4 5 |
Dictionary<Tuple<int, int>, String> timeRanges = new Dictionary<Tuple<int, int>, String>(); timeRanges.Add(new Tuple<int, int>(0, 7), "Within 1 Week"); timeRanges.Add(new Tuple<int, int>(7, 14), "1 Week to 2 Weeks"); |
But how could we represent "Over 2 Weeks"? Apparently the second parameter of the Tuple should be infinity.
Infinity
To represent infinity for an integer, we can use int.MaxValue (it's actually Int32.MaxValue)
So we can solve above problem using following code
1 |
timeRanges.Add(new Tuple<int, int>(14, int.MaxValue), "Over 2 Weeks"); |