What is @ before variable / identifier in C #?

I think my question is different from this: What is @ before a line in C #?

I work at VB.net, so it might be something very simple in C #, but I don't know about that.

I got the following code where I have 10 XML inside a string variable. Please advise which @ character is required before the string Claimsist when calling the LoadXml method in the code snippet below:

private void UploadNewClaims(PMAUser grumble, string companyAbbreviation, string claimsList) { var claimDoc = new System.Xml.XmlDocument(); claimDoc.LoadXml(@claimsList); 
+7
source share
1 answer

In this case, it is completely unnecessary, but allows you to use any keyword as an identifier in C #. It does not change the value of the identifier at all or how it is used - it tells the compiler that you do not want the following characters to be recognized as a keyword.

For example:

 string @int = "hello"; var @void = @int; 

Using it for the claimsList identifier assumes that the person who wrote it does not understand it. The fact that the identifier for a string variable is completely irrelevant here.

Personally, I almost always used this function for extension methods, where, as you know, I called the first @this parameter:

 public static void Foo(this Bar @this) { return @this.Baz() * 2; } 
+20
source

All Articles