我想学习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