{"id":19626571,"url":"https://github.com/softcircuits/ordereddictionary","last_synced_at":"2025-08-02T01:09:42.674Z","repository":{"id":98675114,"uuid":"245526424","full_name":"SoftCircuits/OrderedDictionary","owner":"SoftCircuits","description":".NET library that implements an ordered dictionary.","archived":false,"fork":false,"pushed_at":"2024-03-31T20:00:27.000Z","size":77,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-07T12:18:12.016Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftCircuits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-03-06T22:15:55.000Z","updated_at":"2024-02-29T14:42:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"74e193cf-d270-4c72-9281-7012e879160b","html_url":"https://github.com/SoftCircuits/OrderedDictionary","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FOrderedDictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FOrderedDictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FOrderedDictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftCircuits%2FOrderedDictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftCircuits","download_url":"https://codeload.github.com/SoftCircuits/OrderedDictionary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224098944,"owners_count":17255545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T11:47:02.224Z","updated_at":"2024-11-11T11:47:04.320Z","avatar_url":"https://github.com/SoftCircuits.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OrderedDictionary\n\n[![NuGet version (SoftCircuits.OrderedDictionary)](https://img.shields.io/nuget/v/SoftCircuits.OrderedDictionary.svg?style=flat-square)](https://www.nuget.org/packages/SoftCircuits.OrderedDictionary/)\n\n```\nInstall-Package SoftCircuits.OrderedDictionary\n```\n\n## Introduction\n\nOrderedDictionary is a .NET library that implements an ordered dictionary. It provides all the functionality of `Dictionary\u003cTKey, TValue\u003e` but also maintains the items in an ordered list. Items can be added, removed and accessed by key or index. For compatibility, the class implements the `IDictionary` and `IReadOnlyDictionary` interfaces.\n\n## Examples\n\nOrderedDictionary can be initialized used like any other dictionary. This includes initializing with *index initializers*.\n\n```cs\nOrderedDictionary\u003cint, string\u003e dictionary = new()\n{\n    [101] = \"Bob Smith\",\n    [127] = \"Gary Wilson\",\n    [134] = \"Ann Carpenter\",\n    [187] = \"Bill Jackson\",\n    [214] = \"Cheryl Hansen\",\n};\n```\n\nLike 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.\n\n```cs\nAssert.AreEqual(\"Gary Wilson\", dictionary[127]);\nAssert.AreEqual(\"Bill Jackson\", dictionary.ByIndex[3]);\n```\n\nYou can add items using the `Add()` method, and you can also insert them at a particular location.\n\n```cs\nOrderedDictionary\u003cint, string\u003e dictionary = new();\n\ndictionary.Add(101, \"Bob Smith\");\ndictionary.Add(127, \"Gary Wilson\");\ndictionary.Add(187, \"Bill Jackson\");\ndictionary.Add(214, \"Cheryl Hansen\");\n\ndictionary.Insert(2, 134, \"Ann Carpenter\");\n\nAssert.AreEqual(\"Bob Smith\", dictionary[101]);\nAssert.AreEqual(\"Bob Smith\", dictionary.ByIndex[0]);\nAssert.AreEqual(\"Gary Wilson\", dictionary[127]);\nAssert.AreEqual(\"Gary Wilson\", dictionary.ByIndex[1]);\nAssert.AreEqual(\"Ann Carpenter\", dictionary[134]);\nAssert.AreEqual(\"Ann Carpenter\", dictionary.ByIndex[2]);\nAssert.AreEqual(\"Bill Jackson\", dictionary[187]);\nAssert.AreEqual(\"Bill Jackson\", dictionary.ByIndex[3]);\nAssert.AreEqual(\"Cheryl Hansen\", dictionary[214]);\nAssert.AreEqual(\"Cheryl Hansen\", dictionary.ByIndex[4]);\n```\n\nItems can also be removed using either the key or index.\n\n```cs\nOrderedDictionary\u003cint, string\u003e dictionary = new()\n{\n    [101] = \"Bob Smith\",\n    [127] = \"Gary Wilson\",\n    [134] = \"Ann Carpenter\",\n    [187] = \"Bill Jackson\",\n    [214] = \"Cheryl Hansen\",\n};\n\ndictionary.Remove(134); // Removes 134 - Add Carpenter\ndictionary.RemoveAt(2); // Removes 187 - Bill Jackson\n\nAssert.AreEqual(5 - 2, dictionary.Count);\nAssert.IsTrue(dictionary.ContainsKey(101));\nAssert.IsTrue(dictionary.ContainsKey(127));\nAssert.IsFalse(dictionary.ContainsKey(134));\nAssert.IsFalse(dictionary.ContainsKey(187));\nAssert.IsTrue(dictionary.ContainsKey(214));\n```\n\nYou can also iterate through an `OrderedDictionary` using `foreach`.\n\n```cs\nforeach (KeyValuePair\u003cint, string\u003e item in dictionary)\n{\n    Console.WriteLine(item.Key);\n    Console.WriteLine(item.Value);\n}\n```\n\nTo iterate the keys or values only, you can use the `Keys` or `Values` properies.\n\nThe library also defines the `ToOrderedDictionary()` extension method with several overloads for converting `IEnumerable\u003c\u003e`s to `OrderedDictionary\u003c\u003e`s.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcircuits%2Fordereddictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftcircuits%2Fordereddictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftcircuits%2Fordereddictionary/lists"}