C# @ modifier for methods parameters

后端 未结 6 1603
心在旅途
心在旅途 2021-02-18 13:56

I was using ReSharper plugin on VS2010 and i was generating an interface method. ReSharper put an @ on the parameter name. WHat is that used for?

int Count(Func&         


        
6条回答
  •  一个人的身影
    2021-02-18 14:16

    The @ symbol allows you to use reserved words in a variable name.

    int @class = 1;
    
    void MyMethod(int @goto);
    
    bool @public { get; set; }
    

    As Marc correctly pointed out in his comment and his answer, ReSharper is actually wrong to do this because where is a Contextual Keyword and is not actually a reserved word, so your method will compile without the @.

提交回复
热议问题