Search code examples
c#xml-documentation

Can I use quote marks in an XML documentation comment?


When writing an XML documentation comment in a C# source file, do I need to replace " with "? This question discusses how to replace characters, but does not establish which characters need replacing, aside from establishing that angle brackets do need replacing.


Solution

  • No, just like normal XML, you only need to escape the quotes when they would otherwise have a special meaning. So if your XML documentation contains an attribute and you want a double quote in the attribute value, then you'd either use an attribute or use a single quote for the value start/end:

    /// Foo <element attr="Bar&quot;Baz" />
    /// Foo <element attr='Bar"Baz' />
    

    But it's very rare to need attribute values with quotes in within XML documentation, in my experience. They're almost always references to parameters, members, or list types.