編輯: 我在這裏使用公司屬性,這個概念對於讀這篇文章的人應該是有意義的: 我有2個用於EFImport的構造函數,一個有兩個參數,另一個有三個參數。我的建議是我的構造函數有2個參數沒有被識別。我正在使用new關鍵字,並且以具有3個參數的構造函數完全相同的方式初始化對象,並且它完美地工作。但是具有2個參數的構造函數沒有被識別。再次,我不能在這裏專門提供代碼,但這個概念正是我所問的。我創建了兩個構造函數,但只能使用其中一個創建實例
我需要使用兩個不同的構造函數,一個需要額外的參數,另一個不需要該參數。我不確定爲什麼我無法真正到達只有兩個參數的構造函數。
我有以下構造函數:
public EFImport(string empId, Class A instanceA, IEnumerable<ClassB> instanceB)
{
//do stuff here
}
public EFImport(string empId, Class A instanceA)
{
//do other different stuff here
}
我想這樣調用構造函數:
Public HttpResponseMessage Post([FromBody]string fEmp)
{
//do stuff here
//call constructor here:
//NEW keyword is used here
var fileImp = new EFImport(empId, instanceA, instanceB);
//this works just fine
}
Public HttpResponseMessage Put([FromBody]string empImportId)
{
//do stuff here
//call constructor here:
//NEW keyword used here
var fileImp = new EFImport(empId, instanceA);
//Here it gives me the error stated below
}
錯誤509「EFImport
」不包含一個構造函數需要兩個參數
我究竟做錯了什麼?這兩個構造函數都是公共的,具有3個參數的構造函數完全正常,但編譯器沒有看到帶2個參數的構造函數。我能忽略一些非常簡單的事情嗎
[如何創建一個最小,完整和可驗證例如](http://stackoverflow.com/help/mcve) – Eser
不應該是'ClassA'而不是'ClassA'嗎?整潔計數。 – LarsTech
你確定你發佈了可以編譯的代碼嗎? – 2015-09-04 20:31:25