Using @keyword in C # is a bad idea?

In my naming convention, I use _name for private member variables. I noticed that if I automatically create a constructor with ReSharper, if the member is a keyword, it will generate the escaped keyword. For instance:

class IntrinsicFunctionCall
{
    private Parameter[] _params;
    public IntrinsicFunctionCall(Parameter[] @params)
    {
        _params = @params;
    }
}

Is this generally bad practice or is everything okay? This happens quite often with @params and @interface.

EDIT: this does not actually add a prefix to the variable name. If accessing this variable is from another .NET language, that is, F #, it will be simple params. In fact, in C #, if you write @x, it is exactly equivalent x.

+3
source share
3

. , , .

( , :-)) :

interface IInterfaceFactory<T>
{
   T CreateInstance(params object[] @params);
}

class SomeClass
{
    IMyOtherInterface _interface;

    public IMyOtherInterface Interface
    {
        get { return _interface; }
    }

    public SomeClass(params object[] @params)
    {
        SomeInterface<IMyOtherInterface> interfaceFactory = new SomeInterface<IMyOtherInterface>();
        IMyOtherInterface @interface = interfaceFactory.CreateInstance(@params);
        if (@interface->IsValid())
        {
            _interface = @interface;
        }
        else
        {
            _interface = interfaceFactory.CreateInstance();
        }
    }
}
+6

. - , . , Microsoft , I.

0

, .

, .

int @number;
string @name;

, mix.

int @number;
string _name;
0

Source: https://habr.com/ru/post/1740265/


All Articles