Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# in method, have a @ before parameter [duplicate]

I met a method in C#

int Func(Contact @group)
{
    group.Name = "";
}

What dose the '@' mean ?

like image 591
ProBlc Avatar asked Oct 18 '13 10:10

ProBlc


Video Answer


2 Answers

It's used to escape keywords so you can have parameters named @class or similar, which would otherwise result in a syntax error.

See the relevant portion of the specification: 2.4.2 Identifiers

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.

like image 140
p.s.w.g Avatar answered Oct 08 '22 21:10

p.s.w.g


I believe it is a literal variable.

Keywords such as int, double, etc. cannot be used as variable names, however, you can get round this with the @ symbol:

var int = 3; //compile error

var @int = 3; //okay
like image 34
dav_i Avatar answered Oct 08 '22 20:10

dav_i