【发布时间】:2015-03-13 08:33:04
【问题描述】:
有人知道下面这段代码有什么问题,在VS2013中无法编译吗?
GenericCommand.AddHandlerFactory("MyKey", (cmd, action) =>
{
return (command) =>
{
var result = new SuccessResult() { ResultText = "some example text" };
result.Send(command.Configuration);
};
});
AddHandlerFactory的原型是:
public static void AddHandlerFactory(string key, Func<GenericCommand, Action> handlerFactory)
VS2013编译时显示
不能在此范围内声明名为 command 的局部变量 因为它会给命令赋予不同的含义...... ....
和
委托 System.Func WindowsPhoneTestFramework.Client.AutomationClient.Remote.GenericCommand, System.Action 不接受 2 个参数
EDIT1 将第一个命令重命名为cmd,第一个错误消息就解决了。但它仍然无法编译。
错误信息是:
无法将 lambda 表达式转换为委托类型 Delegate 系统函数 WindowsPhoneTestFramework.Client.AutomationClient.Remote.GenericCommand, System.Action 因为块中的某些返回类型不是 隐式转换为委托返回类型。
【问题讨论】:
标签: c# lambda windows-phone