How do I disable the implicit "this" in C#?

This is a common problem. Microsoft has some recommendations for parameter names but they aren't terribly helpful in your case.

As other responders have mentioned, you cannot "disable" the C# language scope resolution behavior - your best approach is a naming conventions. Others have mentioned "Hungarian" notation - some people have a knee-jerk reaction to this because of the confusion over the original intent of the notation.

My personal approach, has been to use the character 'p' as a prefix to parameter names of public functions. It's unobtrusive, simple, readily identifiable, and easy to enforce with tools like Resharper.

The particular naming convention you choose is a matter of preference and style; however, there is some benefit from being consistent in the practice you select.

Using my suggested naming convention, you would write your constructor to:

class Foo
{
    public Foo(bool pIsAction)
    {
        this.IsAction = pIsAction;
    }

    public bool IsAction { get; private set; }
}

I've just tried your code in Visual Studio 2008. Turning on the in built static analysis yields the following error:

Warning 3 CA1801 : Microsoft.Usage : Parameter 'isAction' of 'Foo.Foo(bool)' is never used. Remove the parameter or use it in the method body.

My suggestion is by turning this on you will find errors like this early on. To enable this choose properties from the context menu on the project, then select the Code Analysis tab and select "Enable Code Analysis on Build"


You could always go back to Hungarian notation [I'm preparing to get flamed as I type this]. If you can deal with the ugliness, it would solve your problem. This is a suggestion, not a reccomendation.

Alternately, I'm pretty gosh darned sure that static code analysis will catch this and warn you about it. Try FxCop.

EDIT

I have been using Resharper for over a year now, and I do know that it is very smart about assisting you in a case sensitive way. Among other benefits, your intellisense problem will be solved by installing Resharper.

EDIT 2

I just checked. Neither FxCop, nor Resharper catches this error directly. What both do catch is the fact that the isAction parameter is unused in the Foo method. In this case, the warning would clue you in to the mistake. In cases where the parameter is used in another way within the method, it might slip through static code analysis.


FxCop will complain about this because the isAction parameter is never used. Specifically it will pull rule CA1801:ReviewUnusedParameters.

Personally I've always felt that the C# compiler should give a warning about unused parameters.