直播? Ctype?少了什么东西 ? [英] Directcast ? Ctype ? what's missing ?

查看:81
本文介绍了直播? Ctype?少了什么东西 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我可以在[test]语句之下无法工作?



我试图将我的班级[KDM_USERSETTINGS]单个实例转换为对象然后返回进入同一个类的另一个实例



当试图将对象转换回新实例时代码中断

我错过了什么?



(在实际应用中我试图在两个dll之间复制数据)



<登记/>


昏暗OBJ作为对象= {CTYPE(原始,KDM_UserSettings)} 

尺寸我作为新KDM_UserSettings

I = DirectCast(OBJ,KDM_UserSettings)







谢谢



乔治·

解决方案
你有在两个不同的地方定义KDMUser_Settings,即使它们具有相同的名称和结构<? br />


这是.NET中常见的误解,即使这两种类型看起来完全相同,他们不能在彼此之间施放。有很多方法,但它主要使用非托管代码和指针。


Why can I get below [test] statement not to work ?

I' trying to convert my class [KDM_USERSETTINGS] single instance into an object and then back into another instance of the same class

The code breaks when trying to cast back the object into the new instance
What Am I Missing ?

(In the actual app I'm trying to copy the data between two dll's)



Dim OBJ As Object = {CType(Original, KDM_UserSettings)}

              Dim I As New KDM_UserSettings

              I = DirectCast(OBJ, KDM_UserSettings)




Thanks

Georg

解决方案

Do you have KDMUser_Settings defined in two different places, even though they have the same name and structure?

This is a common misconception in .NET, even though the two types look exactly the same, they cannot be cast between each other. There are ways around this but its mostly using unmanaged code and pointers.


这篇关于直播? Ctype?少了什么东西 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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