'objType' is not defined… Actually, it is, so why is this happening?

一笑奈何 提交于 2019-12-30 11:19:08

问题


As you seen in this picture below, for some reason my DirectCast wont except ANYTHING for the second argument. It says it requires a type, but, it won't take any object at all!

Thanks for any help! I'm using VB.net so all .net answers are acceptable :)

EDIT

Ok, so apparently I'm not giving it the right kind of type. Could somebody please clarify this? Assuming the type it needs to cast to is gridElement, what should I replace objType with?


回答1:


DirectCast requires an object prototype (i.e. just giving it the intended class name) rather than a System.Type descriptor object. To cast an object using a System.Type, you will want to utilize CTypeDynamic():

Return CTypeDynamic(createElementByIdAndLayer.MemberwiseClone(), objType)

The error is essentially telling you a class with the type name "objType" does not exist.




回答2:


Its expecting a "Type", not a "Type Object".

What is the return value of the function?



来源:https://stackoverflow.com/questions/7534718/objtype-is-not-defined-actually-it-is-so-why-is-this-happening

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!