I am confused by getting the following error:
Unable to cast object of type 'System.Single' to type 'System.Int32'.
I am fetching data and iterating them as follows:
public MyFault
{
public int fault_throw { get; set; }
}
protected List<MyFault> myfaults = new List<MyFault>();
foreach (var package in packages2)
{
// the following line throws an error
myfaults.Add(new MyFault {fault_throw=(int)(package["fault_throw"])});
}
System.Single is a single-precision floating-point number. And I think it is boxed as object in package["fault_throw"]. And you can not unbox a float to an int. You can use the Convert.ToInt32()
Method, if you want to convert a boxed float to an integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With