English 中文(简体)
C# 反应堆问题
原标题:C# Constructor Question

我对C#有一个构造问题。

我有这一类:

public partial class Signature : Form, ISignature
{
    private readonly SignatureMediator mediator;

    public Signature(SignatureMediator mediator)
    {
        this.mediator = mediator;
        InitializeComponent();
    }

    .... more stuff
 }

我愿这样作:

    public SignatureMediator(int someValue, int otherValue, int thirdValue)  
       : this(new Signature(this), someValue, otherValue, thirdValue)
    // This is not allowed --^
    {
        // I don t see anyway to get this in to the ":this" part.
        //Signature signature = new Signature(this);

    }            


    public SignatureMediator(ISignature form, int someValue, int otherValue, int thirdValue)
    {
        SigForm = form;
        SomeValue= someValue;
        OtherValue= otherValue;
        ThirdValue= thirdValue;
    }

www.un.org/Depts/DGACM/index_russian.htm

在不重复固定价值分配的情况下建立这种制度是否有任何进展?

最佳回答

如果<代码>tature ,则将第二位构造改为;(>tature para amount? 然后,你可以从第一名建筑商通过<代码>null,以便了解你想要的行为。

public SignatureMediator(int someValue, int otherValue, int thirdValue)  
   : this(null, someValue, otherValue, thirdValue)
{
}            

public SignatureMediator(ISignature form, int someValue, int otherValue, int thirdValue)
{
    if (form == null)
    {
        SigForm = new Signature(this);
    }
    else
    {
        SigForm = form;
    }

    SomeValue = someValue;
    OtherValue = otherValue;
    ThirdValue = thirdValue;
}
问题回答

无疑,在建筑链条电话中,你不能使用<条码>,因此,你不得不在建筑商的身体上叫它。 最为干净的方式是将共同的初始化法引入一种单独的方法,例如:

public SignatureMediator(int someValue, int otherValue, int thirdValue)  
{
    Initialise(someValue, otherValue, thirdValue)
    SigForm = new Signature(this);
}            


public SignatureMediator(ISignature form, int someValue, int otherValue, int thirdValue)
{
    Initialise(someValue, otherValue, thirdValue)
    SigForm = form;
}

private void Initialise(int someValue, int otherValue, int thirdValue)
{
    SomeValue= someValue;
    OtherValue= otherValue;
    ThirdValue= thirdValue;
}

如果构造一个<条码>的标语真正廉价,那么你就可以避免额外方法,而只有第二位构造人称第一种方法,然后再用超值写出它产生的SigForm值。

我从未见过一位调解人,负责在双方之间制造它所调解的物品。 如果是的话,它将把制造问题与调解混为一谈,即便没有你的同义挑战,调解也似乎很模糊。

为什么不能以传统的“GoF”模式所建议的方式将调解人通过签署? 你的客户建造调解人,然后将调解人交给调解人之间每一物体的施工者。 如果这种错误很容易发生,那么你的物体可使用建筑设计或工厂方法建造。

你可以把“这”称为一种论点,因为物体是构造的。 否则,你就不得不把建筑工作链起来:

public SignatureMediator(int w, int x, int y, int z)  
   : this(x,y,z)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签