c# - Comparison of various types -
i'm trying make code comparing 2 object in various types stored system.object
.
i tried code:
object = getvalue(..); object b = getvalue(..); type t = findcommontype(a, b); return < b;
the result of getvalue
instance in 1 of following types: long, double, string, bool , my own class
method findcommontype
returns instance of system.type
, are:
if actual type of passed arguments identical, returns
typeof(a)
in respecttypeof(b)
.if types different, converts
b
typeof(a)
, returnstypeof(a)
.the returning instance of
system.type
1 of following:typeof(long)
,typeof(int)
,typeof(double)
,typeof(float)
.
for example, if a = (long)123
, b = "123"
, converts b
long
, returns typeof(long)
, code compares them.
but comparison a < b
unsuccessful.
how can compare 2 objects in various types in respect type t
holds?
Comments
Post a Comment