2009-12-11 43 views
0

的使用我有一個構造函數在我的Windows窗體可以構造器鏈接到位重載構造

public frmSecondarySEC(int intPrimaryDocumentId, int intSecondaryDocumentId, string strStateCode, int intCountyId, string strPrimaryDocTypeName, string strPrimaryDocTypeCode, string strDealName, string strLoanNumber, int intDealId, string strDealType, string strCountyName, bool blIsFileReview) 
{ 

} 

現在我需要一個額外的參數傳遞給這個構造函數。爲此,我創建了此構造函數的重載版本,以便使用原始構造函數的其他類不會分解。僅有的差異是添加了新參數。

public frmSecondarySEC(int intPrimaryDocumentId, int intSecondaryDocumentId, string strStateCode, int intCountyId, string strPrimaryDocTypeName, string strPrimaryDocTypeCode, string strDealName, string strLoanNumber, int intDealId, string strDealType, string strCountyName, bool blIsFileReview,string primaryDocumentTitle) 
{ 
} 

現在,因爲它們共享黎民初始化代碼,我試圖構造函數鏈

public frmSecondarySEC(int intPrimaryDocumentId, int intSecondaryDocumentId, string strStateCode, int intCountyId, string strPrimaryDocTypeName, string strPrimaryDocTypeCode, string strDealName, string strLoanNumber,int intDealId, string strDealType, string strCountyName, bool blIsFileReview) : this(int intPrimaryDocumentId, int intSecondaryDocumentId, string strStateCode, int intCountyId, string strPrimaryDocTypeName, string strPrimaryDocTypeCode, string strDealName, string strLoanNumber, int intDealId, string strDealType, string strCountyName, bool blIsFileReview) 
{ 
} 

但是我對這個部分

:this(int intPrimaryDocumentId 

它說

無效的表達得到一個錯誤term'int'.Am我使用構造函數鏈或i的錯誤實現t可以通過其他方式完成。我想防止重複的代碼。請建議。

回答

6

它知道類型,只是傳遞參數。

:this(intPrimaryDocumentId) 
1

你可以調用從另一個像這樣:

public M (int k) { } 

public M() : this(1) { } 

所以,你不重新定義變量,你只是通過它,如果你是調用一個方法。

1

鏈接構造函數時,不再指定類型。它應該是:

public frmSecondarySEC(int intPrimaryDocumentId, int intSecondaryDocumentId, string strStateCode, int intCountyId, string strPrimaryDocTypeName, string strPrimaryDocTypeCode, string strDealName, string strLoanNumber,int intDealId, string strDealType, string strCountyName, bool blIsFileReview) 
    : this(intPrimaryDocumentId, intSecondaryDocumentId, strStateCode, intCountyId, strPrimaryDocTypeName, strPrimaryDocTypeCode, strDealName, strLoanNumber, intDealId, strDealType, strCountyName, blIsFileReview) 

另外,您應該考慮是否所有這些參數都是必需的。認真。