本文介绍了安全C#:如何保存指针或引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好.
有可能吗
持有对象引用
在C#的安全类上下文中,请? :-O :)
Hello.
Would it be possible
to hold an object reference
in the safe class context of C#, please ? :-O :)
public abstract class WizardPage : UserControl
{
private Wizard wizard;
public WizardPage(ref Wizard wizardRef)
{
wizard = wizardRef; // hmmm... is it just a copy now ? :)
}
public abstract void OnBack();
public abstract void OnActivate();
public abstract void OnNext();
...
}
谢谢!
推荐答案
private Wizard wizard;
public WizardPage(Wizard wizard)
{
this.wizard = wizard;
}
{
object o1 = new object(); // o1 is a reference to an real instance in the memory
object o2; // o2 is a empty reference yet
o2 = o1; // o2 is a reference to the same instance
// referenced by o1, not a reference to an own instance (!!)
}
这篇关于安全C#:如何保存指针或引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!