CommentCollection class

Provides typed access to a collection of Comment nodes.

To learn more, visit the Working with Comments documentation article.

public class CommentCollection : NodeCollection


Count { get; }Gets the number of nodes in the collection.
Item { get; }Retrieves a Comment at the given index. (2 indexers)


Add(Node)Adds a node to the end of the collection.
Clear()Removes all nodes from this collection and from the document.
Contains(Node)Determines whether a node is in the collection.
GetEnumerator()Provides a simple “foreach” style iteration over the collection of nodes.
IndexOf(Node)Returns the zero-based index of the specified node.
Insert(int, Node)Inserts a node into the collection at the specified index.
Remove(Node)Removes the node from the collection and from the document.
RemoveAt(int)Removes the node at the specified index from the collection and from the document.
ToArray()Copies all nodes from the collection to a new array of nodes.


Shows how to mark a comment as “done”.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Helo world!");

// Insert a comment to point out an error. 
Comment comment = new Comment(doc, "John Doe", "J.D.", DateTime.Now);
comment.SetText("Fix the spelling error!");

// Comments have a "Done" flag, which is set to "false" by default. 
// If a comment suggests that we make a change within the document,
// we can apply the change, and then also set the "Done" flag afterwards to indicate the correction.

doc.FirstSection.Body.FirstParagraph.Runs[0].Text = "Hello world!";
comment.Done = true;

// Comments that are "done" will differentiate themselves
// from ones that are not "done" with a faded text color.
comment = new Comment(doc, "John Doe", "J.D.", DateTime.Now);
comment.SetText("Add text to this paragraph.");

doc.Save(ArtifactsDir + "Comment.Done.docx");

See Also