# Collections

We briefly introduced [MementoEntity and MementoEntityCollection](/release-1/memento/change-tracking-service/memento-entities.md) and seen how to [track changes in a simple graph](/release-1/memento/change-tracking-service/handling-change-tracking/simple-model.md).

We can go further and introduce collection change tracking:

```csharp
var list = new MementoEntityCollection<String>();
memento.Attach( list );

list.Add( "a" );
list.Add( "b" );
list.Add( "c" );

var count = list.Count; //3

memento.Undo();
var _count = list.Count; //2

memento.Redo();
var __count = list.Count; //3
```

The `MementoEntityCollection<T>` being a memento entity will keep track of changes applied to collection structure. Each change will be tracked, starting from `Add` and `Remove` to `Clear`, `Insert`, `InsertAt`, etc...

```csharp
var list = new MementoEntityCollection<Person>();
memento.Attach( list );

list.Add( new Person() );
```

Adding a `MementoEntity`, such as `Person`, will automatically trigger the memento that will start tracking the `Person` instance:

```csharp
var list = new MementoEntityCollection<Person>();
memento.Attach( list );

var person = new Person();
list.Add( person );

person.FirstName = "name";

memento.Undo(); //the person first name is reverted
memento.Undo(); //the person instance is removed from the collection
memento.Redo(); //the person instance is added once again to the collection
```

As expected the changes stack is handled in the correct order. The next step is to understand how to [handle change tracking in complex objects graph](/release-1/memento/change-tracking-service/handling-change-tracking/complex-graph.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.radicalframework.com/release-1/memento/change-tracking-service/handling-change-tracking/collections.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
