-1

It's difficult to explain. I've created a Infinity Class, Infinity< t > , for example Infinity < int >, and it contains a bool that says if the infinity is + or - and operators overloading, so you can do all of this: infinity + int, int - infinity, infinity > int, infinity < infinity, -infinity, etc...

And that's great, it's exactly what I wanted, but the problem is that, to use it you have to declare a variable as Infinity, and I don't want that. I need to declare a integer, for example, and assign this Infinity to it, and then change its value when it's needed to a normal int. Example:

int data = +Infinity;
......
n = 3;
if (n < data) data = n;

So the question is, how can I assign this Infinity to any other kind of variable ( to a integer, double, float, etc), but still using the Infinity operators.

I mean, passing a Infinity object as a integer for example, and use its operators until I assign a normal int value to it. Is this possible? Thanks.

  • 2
    What about `double.PositiveInfinity` and `double.NegativeInfinity`? – Omar Jan 18 '15 at 14:32
  • What @Fuex said. Otherwise, the closest you are going to get is an implicit cast. – Mitch Jan 18 '15 at 14:33
  • Sorry did not understand question correctly. Can you explain by pseudo code? If you have generic type then int data = +Infinity; should work. – Amit Jan 18 '15 at 14:33
  • @Fuex I know there are already other Infinity classes, but I wanted to build my own Infinity class, that's the point... Thanks anyway – Oscar Sales Salvador Jan 18 '15 at 16:18

1 Answers1

0

You can converts the value of the specified value to an equivalent Boolean value. Like,

int x=1,2,3;    //It can be anything (int,double etc)
bool result;
if(result=Convert.ToBoolean(x==2)
{ Console.WriteLine("We Won");
    }