# Topological Sorting

TopoSort is a static class that provides functionality to perform a topological sort on a collection of items with dependencies.

## Sort

This method takes a source collection of items and a function that returns the dependencies of each item. It returns a sorted list of items based on their dependencies.

#### Example:

```csharp
var items = new List<string> { "A", "B", "C", "D" };
var dependencies = new Dictionary<string, List<string>>
{
    { "A", new List<string> { "B", "C" } },
    { "B", new List<string> { "C", "D" } },
    { "C", new List<string> { "D" } },
    { "D", new List<string>() }
};

var sortedItems = TopoSort.Sort(items, item => dependencies[item]);
// sortedItems will be ["D", "C", "B", "A"]
```


---

# 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.perigee.software/core-modules/utility-classes/topological-sorting.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.
