VB.Net中的DirectCast错误 [英] DirectCast Error In VB.Net

查看:204
本文介绍了VB.Net中的DirectCast错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,这是Vikash Gohil。



我有一个班级,我有以下构造函数。



hello, this is Vikash Gohil.

I have a class in which I have the following constructor.

dim xyz as AppInfo

sub abc (byref Arg1 as object, byref Arg2 as Object)

xyz = DirectCast(Arg2, AppInfo)    

end sub





以上代码通过传递2个参数使用反射执行



Param1类型为OracleTransaction

Param2作为AppInfo类型



以上代码在DirectCast语句中给出错误无法将AppInfo类型的变量转换为AppInfo类型



为什么类型相同时会出错?



Above code is executed using reflection by passing 2 parameters

Param1 as type OracleTransaction
Param2 as type AppInfo

The above code gives error in DirectCast Statement as "Unable to Convert variable of type "AppInfo" to type "AppInfo""

why does it give error when the types are same?

推荐答案

这是因为AppInfo是一种引用类型。请查看本文以获取完整说明 http://visualbasic.about.com/od/learnvbnet/ a / casting1_3.htm [ ^ ]
It''s because AppInfo is a reference type. Have a look at this article for the full explanation http://visualbasic.about.com/od/learnvbnet/a/casting1_3.htm[^]


这不应该是一个问题,因为显然,你要做的第一件事就是将param2转换为AppInfo对象。为什么你甚至在函数头中指定一个Object类型开头?只需将其更改为AppInfo即可完成,无需转换。
This shouldn''t even be a problem as, apparently, the first thing you''re doing is converting param2 to an AppInfo object. Why are you even specifying an Object type in the function header to begin with?? Just change it to AppInfo and be done with it, no conversion necessary.


这篇关于VB.Net中的DirectCast错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆