SoftCircuits.OrderedDictionary
3.0.0
Prefix Reserved
See the version list below for details.
dotnet add package SoftCircuits.OrderedDictionary --version 3.0.0
NuGet\Install-Package SoftCircuits.OrderedDictionary -Version 3.0.0
<PackageReference Include="SoftCircuits.OrderedDictionary" Version="3.0.0" />
paket add SoftCircuits.OrderedDictionary --version 3.0.0
#r "nuget: SoftCircuits.OrderedDictionary, 3.0.0"
// Install SoftCircuits.OrderedDictionary as a Cake Addin #addin nuget:?package=SoftCircuits.OrderedDictionary&version=3.0.0 // Install SoftCircuits.OrderedDictionary as a Cake Tool #tool nuget:?package=SoftCircuits.OrderedDictionary&version=3.0.0
OrderedDictionary
Install-Package SoftCircuits.OrderedDictionary
Introduction
OrderedDictionary is a .NET library that implements an ordered dictionary. It provides all the functionality of Dictionary<TKey, TValue>
but also maintains the items in an ordered list. Items can be added, removed and accessed by key or index. The class implements the IDictionary
interface.
Examples
OrderedDictionary can be initialized used like any other dictionary. This includes initializing with index initializers.
OrderedDictionary<int, string> dictionary = new()
{
[101] = "Bob Smith",
[127] = "Gary Wilson",
[134] = "Ann Carpenter",
[187] = "Bill Jackson",
[214] = "Cheryl Hansen",
};
Like a dictionary, items can by accessed by key. They can also be accessed using a 0-based index. Because it's possible for the key to be of type int
, the ByIndex
property is used to access an item using an index. This prevents any ambiguity between key and index values.
Assert.AreEqual("Gary Wilson", dictionary[127]);
Assert.AreEqual("Bill Jackson", dictionary.ByIndex[3]);
You can add items using the Add()
method, and you can also insert them at a particular location.
OrderedDictionary<int, string> dictionary = new();
dictionary.Add(101, "Bob Smith");
dictionary.Add(127, "Gary Wilson");
dictionary.Add(187, "Bill Jackson");
dictionary.Add(214, "Cheryl Hansen");
dictionary.Insert(2, 134, "Add Carpenter");
Assert.AreEqual("Bob Smith", dictionary[101]);
Assert.AreEqual("Bob Smith", dictionary.ByIndex[0]);
Assert.AreEqual("Gary Wilson", dictionary[127]);
Assert.AreEqual("Gary Wilson", dictionary.ByIndex[1]);
Assert.AreEqual("Add Carpenter", dictionary[134]);
Assert.AreEqual("Add Carpenter", dictionary.ByIndex[2]);
Assert.AreEqual("Bill Jackson", dictionary[187]);
Assert.AreEqual("Bill Jackson", dictionary.ByIndex[3]);
Assert.AreEqual("Cheryl Hansen", dictionary[214]);
Assert.AreEqual("Cheryl Hansen", dictionary.ByIndex[4]);
Items can also be removed using either the key or index.
OrderedDictionary<int, string> dictionary = new()
{
[101] = "Bob Smith",
[127] = "Gary Wilson",
[134] = "Ann Carpenter",
[187] = "Bill Jackson",
[214] = "Cheryl Hansen",
};
dictionary.Remove(134);
dictionary.RemoveAt(2); // Removes 187 - Bill Jackson
Assert.AreEqual(5 - 2, dictionary.Count);
Assert.IsTrue(dictionary.ContainsKey(101));
Assert.IsTrue(dictionary.ContainsKey(127));
Assert.IsFalse(dictionary.ContainsKey(134));
Assert.IsFalse(dictionary.ContainsKey(187));
Assert.IsTrue(dictionary.ContainsKey(214));
You can iterate through an OrderedDictionary
using `foreach.
foreach (KeyValuePair<int, string> item in dictionary)
{
Console.WriteLine(item.Key);
Console.WriteLine(item.Value);
}
To iterate the keys or values only, you can use the Keys
or Values
properies.
The library also defines the ToOrderedDictionary()
extension method with several overloads for converting IEnumerable<>
s to OrderedDictionary<>
s.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SoftCircuits.OrderedDictionary:
Repository | Stars |
---|---|
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
|
Added the ContainsValue() method; Minor code changes; Reworked documentation and unit tests.
BREAKING CHANGES:
Default enumerator now iterates the KeyValuePair<TKey, TValue>s rather than iterating the values. To iterate values, use the Values property. To iterate keys, use the Keys property.
The `Contains` method now looks for a matching KeyValuePair<TKey, TValue> using the default comparer, instead of looking for a matching key. An overload is provided that accepts a custom equality comparer.