Neelakandan K
Neelakandan K

Reputation: 161

How to add List type code example in XML comment?

I have used below XML comment,

    /// <example> 
    /// This example shows how to use <see cref="SampleCollection"/> property.
    /// <code>
    /// class TestClass 
    /// {
    ///      List<string> collection = new List<string>();
    ///      collection.Add("Column1");
    ///      collection.Add("Column2");
    ///      this.SampleCollection = collection;
    /// }
    /// </code>
    /// </example>        
    public List<string> SampleCollection
    {
        get;
        set;
    }

But it has the following warning error,

XML comment on 'SampleCollection' has badly formed XML -- 'End tag 'code' does not match the start tag 'string'.'

because List definition has the <string>. So it considered that as XML tag.

Is there any way to resolve this?

Upvotes: 5

Views: 1069

Answers (1)

SLaks
SLaks

Reputation: 887275

Use a CDATA block to embed raw text within the XML:

<![CDATA[
List<string> ...
]]>

Upvotes: 7

Related Questions