가능한 중복 :
Why is the ‘this’ keyword required to call an extension method from within the extended class확장 메서드에 "this"가 필요합니까?
비주얼 스튜디오에게 2012
Sitefinity 5. *을 사용하여 네임 스페이스 Telerik.Sitefinity.Web.UI
에 System.Web.UI.MasterPage
에 대한 몇 가지 확장 방법을 정의합니다.
using Telerik.Sitefinity.Web.UI;
namespace MyWebApp
{
public partial class MyMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
/// hide common page elements.
/// GetIndexRenderMode() returns "Normal" if the page is being rendered
/// normally, but not if the search engine is indexing the page.
if (this.GetIndexRenderMode() != IndexRenderModes.Normal)
{
headerPlaceholder.Visible = false;
footerPlaceholder.Visible = false;
navigationPlaceholder.Visible = false;
}
}
}
}
단, I는 this
제거하면 : I가 네임 스페이스에 대한 참조를 포함하면
, I는 일반적으로 렌더링하거나 내부 검색 엔진되고있는 페이지를 나타내는 특정 확장 방법을 사용하여 if(...)
문에서 컴파일러는 더 이상 확장 메서드를 찾지 않습니다.
무엇을 제공합니까? 전에는 this
이 필요한 경우를 본 적이 없습니다. 단, 클래스 멤버와 인터페이스 멤버 또는 매개 변수 사이의 모호성을 해결할 수 있습니다.
"연장형 메서드에서 필수 항목"이 필요합니까? " 더 나은 표제가 될 것입니다. –
"this"는 이름 확인에 필요합니다. –
오히려 다음 전체 지점 체크를 반복합니다 - http://stackoverflow.com/questions/3510964/why-is-the-this-keyword-required-to-call-an-extension-method-from-within – Kami