How to represent integer infinity?

c#, infinity

Solution

If you don't need the full range of integer values, you can use the `int.MaxValue` and `int.MinValue` constants to represent infinities.

However, if the full range of values is required, I'd suggest either creating a wrapper class or simply going for doubles.

Problem

I need a way to represent an integer number that can be infinite. I'd prefer not to use a floating point type (double.PositiveInfinity) since the number can never be fractional and this might make the API confusing. What is the best way to do this? Edit: One idea I haven't seen yet is using int? with null representing infinity. Are there any good reasons not to do this?

Original source