草庐IT

reinterpret_casting

全部标签

c# - 执行标量();用 scope_identity() 生成 "System.InvalidCastException: Specified cast is not valid"

这个问题在这里已经有了答案:Specificcastisnotvalid,whileretrievingscope_identity(4个答案)关闭6年前。我有一个接受各种数据(通过文本框和复选框列表)的表单,在单击事件时,他们将所有数据插入到表中并选择scope_identity,然后将其存储在变量中以在插入时使用它使用循环进入另一个表的复选框列表项根据许多答案和示例,这应该可以完美工作!..但它给了我这个错误:ExceptionDetails:System.InvalidCastException:Specifiedcastisnotvalid.Line66:intNewBrand

c# - 执行标量();用 scope_identity() 生成 "System.InvalidCastException: Specified cast is not valid"

这个问题在这里已经有了答案:Specificcastisnotvalid,whileretrievingscope_identity(4个答案)关闭6年前。我有一个接受各种数据(通过文本框和复选框列表)的表单,在单击事件时,他们将所有数据插入到表中并选择scope_identity,然后将其存储在变量中以在插入时使用它使用循环进入另一个表的复选框列表项根据许多答案和示例,这应该可以完美工作!..但它给了我这个错误:ExceptionDetails:System.InvalidCastException:Specifiedcastisnotvalid.Line66:intNewBrand

c# - Cast vs 'as' 运算符重访

我知道已经有几篇文章讨论了强制转换和as运算符之间的区别。他们大多重申相同的事实:as运算符不会抛出异常,但如果转换失败则返回null因此,as运算符仅适用于引用类型as运算符不会使用用户定义的转换运算符然后答案往往会无休止地争论如何使用或不使用其中一个或另一个以及每个的优缺点,甚至他们的表现(我一点也不感兴趣)。但是这里还有更多的东西在起作用。考虑:staticvoidMyGenericMethod(Tfoo){varmyBar1=fooasBar;//compilesvarmyBar2=(Bar)foo;//doesnotcompile('Cannotcastexpressiono

c# - Cast vs 'as' 运算符重访

我知道已经有几篇文章讨论了强制转换和as运算符之间的区别。他们大多重申相同的事实:as运算符不会抛出异常,但如果转换失败则返回null因此,as运算符仅适用于引用类型as运算符不会使用用户定义的转换运算符然后答案往往会无休止地争论如何使用或不使用其中一个或另一个以及每个的优缺点,甚至他们的表现(我一点也不感兴趣)。但是这里还有更多的东西在起作用。考虑:staticvoidMyGenericMethod(Tfoo){varmyBar1=fooasBar;//compilesvarmyBar2=(Bar)foo;//doesnotcompile('Cannotcastexpressiono

ERROR Executor: Exception in task 0.0 in stage 1.0 (TID 1)Long cannot be cast to java.lang.String

问题尝试使用spark写入Hbase报错这是报错行,rowkey的id这个字段是我使用sparkSQL自带的函数临时添加的,打印schema发现是long类型原因javaLong类型好像不能getAs为String,所以报错了解决将这个字段转换为String再次尝试

c# - 获取 "unable to cast PersistentGenericSet to ISet"错误

我收到这个错误:Unabletocastobjectoftype'NHibernate.Collection.Generic.PersistentGenericSet1[IocWinFormTestEntities.People]'totype'System.Collections.Generic.ISet1[IocWinFormTestEntities.People]'.实体:publicclassEvent{publicEvent(){this.People=newHashSet();}publicvirtualGuidId{get;privateset;}publicvirtua

c# - 获取 "unable to cast PersistentGenericSet to ISet"错误

我收到这个错误:Unabletocastobjectoftype'NHibernate.Collection.Generic.PersistentGenericSet1[IocWinFormTestEntities.People]'totype'System.Collections.Generic.ISet1[IocWinFormTestEntities.People]'.实体:publicclassEvent{publicEvent(){this.People=newHashSet();}publicvirtualGuidId{get;privateset;}publicvirtua

c# - 通过 cast 或 Convert.ToSingle() 将 double 转换为 float?

在C#中,我可以通过强制转换(float)或Convert.ToSingle()将double转换为float。doublex=3.141592653589793238463;floata=(float)x;floatb=Convert.ToSingle(x);a和b变得相等。这两种技术之间有什么区别吗?我应该更喜欢哪一个?为什么? 最佳答案 来自.NETreferencesource:publicstaticfloatToSingle(doublevalue){return(float)value;}因此,您的答案是它们在本质上完

c# - 通过 cast 或 Convert.ToSingle() 将 double 转换为 float?

在C#中,我可以通过强制转换(float)或Convert.ToSingle()将double转换为float。doublex=3.141592653589793238463;floata=(float)x;floatb=Convert.ToSingle(x);a和b变得相等。这两种技术之间有什么区别吗?我应该更喜欢哪一个?为什么? 最佳答案 来自.NETreferencesource:publicstaticfloatToSingle(doublevalue){return(float)value;}因此,您的答案是它们在本质上完

c# - 为什么 (int)(object)10m 抛出 "Specified cast is not valid"异常?

为什么这个显式转换会抛出Specifiedcastisnotvalid.异常?decimald=10m;objecto=d;intx=(int)o;但这行得通:intx=(int)(decimal)o; 最佳答案 装箱值只能拆箱为完全相同类型的变量。这个看似奇怪的限制是一个非常重要的速度优化,它使.NET1.x在泛型可用之前变得可行。您可以在thisanswer中阅读更多相关信息.您不想跳过多重投篮,简单的值类型实现了IConvertible接口(interface)。您可以使用Convert类调用:objecto=12m;inti