c# - Converting an integer to an object and back causes InvalidCastException -



c# - Converting an integer to an object and back causes InvalidCastException -

i'm trying store 3 variables in listviewitem's tag object. i'm doing this:

lvi.tag = new object[] { value1, value2, value3 };

this not problem, when seek revert code:

object[] objs = (lvi.tag object[]); int t = (int)objs[0];

it gives me exception system.invalidcastexception. i've tried debugging it, debugger gives me right info

objs = object[] { 1, 93234, 0 }

does have thought happening?

the next code works fine:

class programme { static void main() { listviewitem lvi = new listviewitem(); lvi.tag = new object[] { 1, 93234, 0 }; object[] objs = (lvi.tag object[]); int t = (int)objs[0]; console.writeline(t); } }

so guess have doubles (or decimals or floats), not integers, create sure casting right type:

double t = (double)objs[0];

c# object .net

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -