I think my question is different from this: What's the @ in front of a string in C#?
I work in VB.net, so this may be some simple thing in C#, but I am not aware of this.
I got the following code where I have 10 XML inside a string variable. Please advice what @ symbol is needed in front of the claimsList string variable when calling 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);
It marks the string as a verbatim string literal. In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string.
Unlike Perl's sigils, an @ prefix before a variable name in C# has no meaning. If x is a variable, @x is another name for the same variable.
In C#, Variable names must start with a letter. Variable names are case-sensitive, num and Num are considered different names. Variable names cannot contain reserved keywords. False, In C#, a variable name can not start with a digit and white space character.
In this case it's completely unnecessary, but it allows you to use any keyword as an identifier in C#. It doesn't change the meaning of the identifier at all, or how it's used - it only tells the compiler that you don't want the following characters to be recognized as a keyword.
For example:
string @int = "hello";
var @void = @int;
Using it for an identifier of claimsList
suggests that whoever wrote it doesn't understand it. The fact that the identifier is for a string variable is entirely irrelevant here.
Personally I've pretty much only ever used the feature for extension methods, where I have been known to call the first parameter @this
:
public static void Foo(this Bar @this)
{
return @this.Baz() * 2;
}
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