我在C#中重載方法有點麻煩。我有兩個看起來像這樣的方法。當使用字符串和sting時重載方法的問題[]
public static void Sample(string string1, string string2, string string3,
System.Windows.Forms.MessageBoxButtons buttons)
{}
public static void Sample(string string1, string[] string2, string string3, System.Windows.Forms.MessageBoxButtons buttons)
{}
當我嘗試調用第二種方法時,出現錯誤「無法將字符串[]'轉換爲'字符串'」。我究竟做錯了什麼?
它適用於重載不使用MessageBoxButtons枚舉的方法,但不適用於此方法。
調用代碼如下所示。
string[] myStringArray = new string[] {"this is a test","of overloaded methods"};
Sample("String1",myStringArray,"String2",System.Windows.Forms.MessageBoxButtons.OK);
編輯: 的問題是在我的構建腳本。在創建引用第一個dll的下一個dll之前,並沒有等待dll被創建,所以在dll中引用的地方做了哪些更改。
猜測這是一個不使用IDE的陷阱。
你可以發佈一個簡短但完整的程序來演示問題嗎? – dtb 2010-02-24 14:44:23
同上。我將這些方法複製到測試應用程序中,然後將它們稱爲無錯誤。可能在通話中發生錯誤,而不是功能。 – xcud 2010-02-24 14:46:23