gpt4 book ai didi

c# - 无法将带 [] 的索引应用于类型为 'method group' SinglePageApp1 的表达式。获取 ["/"] 南希

转载 作者:太空狗 更新时间:2023-10-29 17:32:29 36 4
gpt4 key购买 nike

我尝试在 URL 上使用 NancyModules 和 GET 字符串创建一个类,但是方法“Get”告诉我:

"Error CS0021 Cannot apply indexing with [] to an expression of type 'method group' ...."

我的代码:

using System; using System.Collections.Generic; using System.Linq;
using System.Web; using Nancy; using System.Text;

namespace SinglePageApp1 {
public class BloodPresureNancy : NancyModule
{
public BloodPresureNancy()
{

// Get dasn't work
Get["/"] = _ => "Heloooo";
}
}
}

enter image description here

我添加了引用:Nancy、Nancy.Hosting.asp,但它不起作用。

最佳答案

您目前使用的是哪个版本的 Nancy?该语法应该适用于 1.x 版。但是,我认为 Nancy 最近更改了为即将发布的 2.0 版本注册路由的方式。如果你看一下他们在 github 上的样本 https://github.com/NancyFx/Nancy/blob/master/samples/Nancy.Demo.Hosting.Self/TestModule.cs .你会发现你不再像上面那样索引不同的动词,你实际上像引用方法一样引用它们。尝试将您的代码更改为

    Get("/", _ => {        //do work here     });
相反,看看它是否适合你。

关于c# - 无法将带 [] 的索引应用于类型为 'method group' SinglePageApp1 的表达式。获取 ["/"] 南希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39574057/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com