我有一個C#的構造函數問題。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;
}
的: this(new SignatureThis(this)
不允許(在構造函數中使用的this
是不允許的)。
無論如何設置它而不重複int值的賦值?
發佈片段不是獲得最佳答案的最佳方法。你對想象力太過分了。你想實現一個泛型類型,但沒有一個簡短的但完整的列表,你現有的類和接口的努力可能會被浪費。 – 2010-04-13 23:32:04