c# fighting question


first, twin examples:



// works
int foo = 43;
long lfoo = foo;

// doesn't
object foo = (int)43;
long? nullfoo = foo long?; // advantage null
long lfoo = (long)foo; // throws invalidcastexception
if (foo.gettype() == typeof(int))
console.writeline("but foo an int..."); // gets combined out


now, speculation since second doesn't work since boxing. purpose behind formula exercise icomparable. i need proceed need an vigilant presumably enlarged ulong appropriate, it's neither, pitch an error. i don't wish have exercise checks any simple numeric form (byte, int, long, ubyte, ...) i'd rather only locate largest numeric form understanding way. thoughts intelligent here? i unbox object, preferably avoiding reflection, nonetheless i suspect that's wholly way... should i only exercise non-generics chronicle icomparable?



edit:



this seems work, nonetheless seems terrible penetrate around problem. only me?



long lfoo = long.parse(foo.tostring());


Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

why does floated <input> control floated component slip over too distant right ie7, nonetheless firefox?