I’m trying to store 3 variables in a ListViewItem’s Tag object. I’m currently doing it like this:
lvi.Tag = new object[] { value1, value2, value3 };
This is not a problem, but when I try to revert it with this code:
object[] objs = (lvi.Tag as object[]);
int t = (int)objs[0];
It gives me an exception System.InvalidCastException. I’ve tried debugging it, but the debugger gives me the correct information
objs = object[] { 1, 93234, 0 }
Does anyone have an idea what is happening?
The following code works perfectly fine:
So I guess you have doubles (or decimals or floats), but not integers, so make sure that you are casting back to the correct type: