从一个类对象到另一个类对象的类型转换 [英] Typecast from one class object to other
本文介绍了从一个类对象到另一个类对象的类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我有一个应用程序egApplication1.exe有两个calss MyClass1和MyClass2
Dear All,
I have one application e.g.Application1.exe having two calss MyClass1 and MyClass2
Class MyClass1
{
public int i1;
MyClass1()
{
i1 = 1;
}
}
Class MyClass2
{
public static MyClass1 Function1()
{
return new MyClass1();
}
}
我有另一个应用程序,Application2,我在其中添加了Application1.exe引用。我的代码如下所示
I have another aplication, Application2 where i have added Application1.exe reference to it. and my code is like below
Class MyClass3
{
public int i2;
}
main()
{
MyClass3 objMyClass3 = (MyClass3) MyClass2.Function1();
}
但这是错误的。
任何人都可以告诉我如何解决这个问题。
提前谢谢大家。
问候,
Vidi
But this is giving error.
Can any body tell me how to resolve this.
Thank you all in advance.
Regards,
Vidi
推荐答案
这些类彼此无关。你会期待它会做什么?
查看链接阅读:
http://csharp-station.com/Tutorial/CSharp/Lesson08 [ ^ ]
祝你好运!
Those classes have nothing to do with each other. What would you expect it would do?
Check the link to read up on this:
http://csharp-station.com/Tutorial/CSharp/Lesson08[^]
Good luck!
你不能简单地对一个类进行类型转换另一种。
唯一可行的方法是将基类类型化为派生类。
You cannot simply typecast one class into another.
The only way this would work would be typecasting a base class into a derived class.
这篇关于从一个类对象到另一个类对象的类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文