安全C#:如何保存指针或引用? [英] Safe C# : how to hold a pointer or a reference ?
本文介绍了安全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();
...
}
谢谢!
推荐答案
如果Wizard
是一个类(引用类型),则可以不使用ref
就将其传递.
IfWizard
is a class (reference type) then you can just pass it without theref
.
private Wizard wizard;
public WizardPage(Wizard wizard)
{
this.wizard = wizard;
}
也许这个讨论会有所帮助, http: //stackstackflow.com/questions/1696938/c-objects-by-ref [
Maybe this discussion will help, http://stackoverflow.com/questions/1696938/c-objects-by-ref[^]
谢谢! :)
理解:-D:
Thank you ! :)
Understood :-D :
{
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#:如何保存指针或引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文