我想學習C#的代表。編譯此位代碼時,我在主題行中收到此錯誤消息。不能類型「詮釋」隱式轉換爲「Foo.Bar.Delegates.Program.ParseIntDelegate」
不能類型「詮釋」隱式轉換爲「Foo.Bar.Delegates.Program.ParseIntDelegate」
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Foo.Bar.Delegates
{
class Program
{
private delegate int ParseIntDelegate();
private static int Parse(string x)
{
return int.Parse(x);
}
static void Main()
{
string x = "40";
int y = Parse(x); //The method I want to point the delegate to
ParseIntDelegate firstParseIntMethod = Parse(x);
//generates complier error: cannot implicity convert type int
//to 'Foo.Bar.Delegates.Program.ParseIntDelegate'
ParseIntDelegate secondParseIntMethod = int.Parse(x); //Same error
Console.WriteLine("Integer is {0}", firstParseIntMethod());
}
}
}
所以我堅持,直到我能理解它是什麼,我做錯了。如果有人能幫我解決這個問題,我會非常感激。
是,請先參閱,然後調用並獲得相匹配的簽名。多謝你們。 – birdinacage
很樂意幫忙 - 如果這是對你有用,你可能標誌着李的回答是解決你的問題。 –
我如何評價李? – birdinacage