如果您在运行时遇到了“Unable to cast object of type 'System.Int32' to type 'System.Int64'.”的错误,这意味着您尝试将一个Int32类型的对象转换为Int64类型的对象,但是由于类型不匹配而失败。

要解决这个问题,您可以使用以下方法之一:

  1. 使用Convert.ToInt64()方法进行转换:
int myInt = 123;
long myLong = Convert.ToInt64(myInt);
  1. 使用强制类型转换进行转换:
int myInt = 123;
long myLong = (long)myInt;

请注意,如果您的值超出了Int32的范围,您可能需要使用Int64或者BigInteger类型来存储它。

c# object怎么解决Unable to cast object of type SystemInt32 to type SystemInt64

原文地址: https://www.cveoy.top/t/topic/Lbw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录