-5

What's the difference between:

XmlDocumentFragment docFrag = xmlDoc.CreateDocumentFragment();
docFrag.InnerXml = @myString;

and

XmlDocumentFragment docFrag = xmlDoc.CreateDocumentFragment();
docFrag.InnerXml = myString;
user2896152
  • 762
  • 1
  • 9
  • 32
  • 1
    I am not sure what you are asking? – Harry Mar 27 '17 at 16:12
  • 1
    Are you saying `myString` is a variable or a string literal? I don't understand why you'd change the variable name for the 2nd snippet if the only difference was the `@`. – itsme86 Mar 27 '17 at 16:12
  • It's very unclear what exactly you're asking? Could you perhaps elaborate on what issue you're experiencing? – Geoff James Mar 27 '17 at 16:12
  • 2
    Possible duplicate of [What's the use/meaning of the @ character in variable names in C#?](http://stackoverflow.com/questions/91817/whats-the-use-meaning-of-the-character-in-variable-names-in-c) – Sami Kuhmonen Mar 27 '17 at 16:15

1 Answers1

1

The only case when you should use @ with variable name - is when variable name conflicts with keyword. E.g. if you have variable names like @string or @class. In this particular case you don't need to use @.

It is possible also to declare verbatim string literals with @ symbol, but you should use string literal instead of variable in that case:

     docFrag.InnerXml = 
@"<foo>
   <bar/>
</foo>";

Such string literals might span multiple lines, which is handy when you work with xml.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459