gpt4 book ai didi

c# - 为什么 `w("hi")` doesn' t 工作但 `this.w("hi")` 工作?

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:12 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why is the 'this' keyword required to call an extension method from within the extended class

我想本地化我的 MVC 应用程序然后我想使用 w(message) 方法和作为“flem”回答了here我有这段代码:

namespace System.Web.WebPages
{
public static class Localization
{
public static string w(this WebPageBase page, string message)
{
return message;
}
}
}

但是在 razor page(page.cshtml) 我不能使用 @w("hi") 但是 @this.w("hi") 有效。 我想知道为什么 this.method() 有效但 method() 无效?

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