Possible Duplicate:
What's the use/meaning of the @ character in variable names in C#?
C# prefixing parameter names with @
I feel like I should know this and I find it impossible to google. Below is an excerpt from some Linq code I came across:
private static readonly Func<SomeEntities, someThing, List<someThing>> GetReplacement =
(someEntities, thing) => someEntities.someReplacement.Join(someEntities.someThing,
replaces => replaces.new_thing_id,
newThing => newThing.thing_id,
(rep, newThing) => new {rep, newThing}).Where(
@t => @t.rep.thing_id == thing.thing_id).
Select
(
@t => @t.newThing
).ToList().Distinct(new SomeThingComparer()).ToList();
What does the '@' prefix mean in this context?
Usually, the @
prefix is used if you need to use a keyword as an identifier, such as a variable name:
string @string = "...";
The C# spec says the following (emphasis mine):
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.
Since t
is not a keyword, I'd say that the @
should be removed in your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With