Obviously the meaning of "similiar" will be application-dependent.
In my case, I'd like to classify int
, Int32
, UInt16
and Byte
(and other integer types) to be "similar". Same for float
, double
and Decimal
(and other floating point types).
One possible solution might be:
if ( (myObject is int) ||
(myObject is Byte) ||
...)
{
// Do something with integer types
}
else if ( (myObject is float) ||
(myObject is double) ||
...)
{
// Do something with floating point types
}
However, this seems overly complex and buggy.
Is there a more efficient way to determine if an Object
is "an integer" or "a floating point number" or "a string"?
UPDATE
Some missing information. Using:
- Visual Studio 2019 Professional v16.8.2
- Library targets .NET 4.5 (based on other libraries in the solution) which uses C# 5.0