I am having as stream of objects, which can be either type of number like int, short, long, float etc...
What is the best way to convert it into a number. Best way could be something
ToNumber(object oNumber)
// Best magic could be
var number = (somemagic) oNumber;
float operator1 = oNumber is int
? (float)(int)oNumber
: oNumber is long
? (float)(long)oNumber
: oNumber is float
? (float)oNumber
: (float)(int)oNumber;
assuming float will be able to take all number expect double
I believe Convert.ToSingle
will be able to handle any "core" numeric type you throw at it.
See more on this question at Stackoverflow