本文介绍了将变量发送到已实例化的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以将变量发送到已实例化的类吗?例如:
1. Object1正在运行并创建Object2….
2. Object2完成工作并希望将结果发送回对象1
3.但是……. Object1已经从userControl类继承.因此,object2不会继承objet1
Can you send variables to an already instantiated class? For example:
1. Object1 is running and creates Object2….
2. Object2 finishes his job and wants to send the result back to object 1
3. But……. Object1 already inherits from a userControl class. Therefore object2 does not inherit objet1
推荐答案
class Object1 : UserControl
{
public void Foo()
{
Object2 obj2 = new Object2();
obj2.Completed += Obj2_Completed;
obj2.SomeFunc();
}
void Obj2_Completed(object sender, EventArgs e)
{
}
// ...
}
class Object2
{
public event EventHandler Completed;
public void SomeFunc()
{
//.. do stuff
if (this.Completed != null)
this.Completed(this, EventArgs.Empty);
}
//...
}
这篇关于将变量发送到已实例化的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!