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.
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
So we can solve above problem using following code
timeRanges.Add(new Tuple<int, int>(14, Int.MaxValue), "Over 2 Weeks");
The post C# Int (Integer) Infinity appeared first on Redino blog.