Ou C5 para resumir, é uma biblioteca de classes genéricas para coleções implementada no .Net 2.0 (também compatível com Mono) para C# e outras linguagens CLI. Foi desenvolvida pela IT University of Copenhagen.
Comparando com outras bibliotecas para collections, incluindo a biblioteca padrão System.Collections.Generic, a C5 possui estruturas de dados mais ricas, na classe da Microsoft algumas coleções como array lists e linked lists possuem funcionalidades similares mas não implementam uma interface em comum. Isso pode dificultar um pouco as coisas no momento do entendimento de como a biblioteca funciona.
A C5 nesse aspécto é mais fácil de entender, já que o desenvolvimento foi feito sob uma política restrita de codificar visando interfaces comuns entre as estruturas de dados.
Why yet another generic collection library?
There are already other generic collection libraries for C#/CLI, including the System.Collections.Generic namespace of the CLI or .NET Framework class library (included with Microsoft Visual Studio 2005), and the PowerCollections library developed by Peter Golde . The CLI collection library as implemented by Microsoft .NET Framework 2.0 provides a limited choice of data structures. In general, the CLI Framework library has a proliferation of method variants and rather poor orthogonality. Collection implementations such as array lists and linked lists have much the same functionality but do not implement a common interface. This impairs the learnability of the library. Some of these design decisions are well-motivated by the use of the CLI class library in contexts where nano-second efficiency is more important than rich functionality, and the need to support also rather resource-constrained run-time systems.
Thus, in our opinion, C5 provides the most powerful, well-structured and scalable generic collections library available for C#/CLI. However, although the size of the compiled C5.dll is only about 300 KB, you probably would not choose to use it on your .NET 2.0 Compact Framework wristwatch just now.
Exemplo simples de implementação:
using System;
using C5;
using SCG = System.Collections.Generic;
namespace GettingStarted {
class GettingStarted {
public static void Main(String[] args) {
IList names = new ArrayList();
names.AddAll(new String[] { “Hoover”, “Roosevelt”,
“Truman”, “Eisenhower”, “Kennedy” });
// Print list:
Console.WriteLine(names);
// Print item 1 (”Roosevelt”) in the list:
Console.WriteLine(names[1]);
// Create a list view comprising post-WW2 presidents:
IList postWWII = names.View(2, 3);
// Print item 2 (”Kennedy”) in the view:
Console.WriteLine(postWWII[2]);
// Enumerate and print the list view in reverse chronological order:
foreach (String name in postWWII.Backwards())
Console.WriteLine(name);
}
}
}
O exemplo mostra o uso de uma ArrayList<T> através da interface IList<t>, e mostra como imprimir a lista inteira, como indexar a lista e como ordena-los de forma reversa. Para compilar e rodar o programa exemplo você vai precisar ter instalada a versão compilada da bilbioteca, C5.dll.
Binários, source code e uma detalhada documentação podem ser encontrados aqui.