{"id":64228,"date":"2022-02-09T07:10:27","date_gmt":"2022-02-09T06:10:27","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=64228"},"modified":"2022-07-13T11:50:18","modified_gmt":"2022-07-13T09:50:18","slug":"csharp-sortedlist","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-sortedlist\/","title":{"rendered":"SortedList in C#"},"content":{"rendered":"<p>A SortedList in C# is a <a href=\"https:\/\/code-maze.com\/dotnet-collections-ienumerable-iqueryable-icollection\/\" target=\"_blank\" rel=\"noopener\">collection<\/a> of key-value pairs that must be sorted at any given point in time based on its keys. This data structure guarantees that whenever we add or remove elements from any point in the list, the order of the list will remain the same. In this article, we will discuss how to create and use this data structure in our C# applications.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/collections-csharp\/SortedListInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2>What Is a SortedList in C#?<\/h2>\n<p>As we stated in our introduction, a sorted list is made up of key-value pairs that must always be sorted based on its keys. In C#, we get this using the <code>SortedList<\/code> class. Essentially, this class behaves just like a regular <code>List&lt;T&gt;<\/code>, but has two primary differences;<\/p>\n<ul>\n<li>It gets sorted once we add or remove elements to or from it<\/li>\n<li>It stores a list of <code>KeyValuePair&lt;TKey, TValue&gt;<\/code> instead of a single type <code>T<\/code><\/li>\n<\/ul>\n<p>In fact, we can argue that the <code>SortedList<\/code> is a hybrid between a <a href=\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\" target=\"_blank\" rel=\"noopener\">Dictionary&lt;TKey, TValue&gt;<\/a> and a <code>List&lt;T&gt;<\/code>. This has some operational advantages, as well as disadvantages.<\/p>\n<p>Let&#8217;s compare adding new elements into a <code>List<\/code> object, to adding elements into a <code>SortedList<\/code>:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/list_vs_sorted_list-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-65263\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/list_vs_sorted_list-1.png\" alt=\"Insertion: List vs SortedList\" width=\"934\" height=\"345\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/list_vs_sorted_list-1.png 934w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/list_vs_sorted_list-1-300x111.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/list_vs_sorted_list-1-768x284.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>When we add a new element to a List, our list class will simply append the element to the end of the collection in the order in which we added them. For the SortedList however, our class will always sort the contents of the list to decide the appropriate position to insert our new element.<\/p>\n<h2>How to Create a SortedList in C#<\/h2>\n<p>There are two versions of this class available in C#; the generic and non-generic versions. They differ in how we create them, and some nuances in how we access them.<\/p>\n<h3>Generic SortedList<\/h3>\n<p>The generic <code>SortedList<\/code> is available under the <code>System.Collections.Generic<\/code> namespace. As with all generics, when creating a new object, we have to define the types of the key and value that is, <code>TKey<\/code> and <code>TValue<\/code> respectively.<\/p>\n<p>Let&#8217;s create a generic SortedList that takes <code>int<\/code> keys and <code>string<\/code> values:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var myList = new SortedList&lt;int,string&gt;();\r\n<\/pre>\n<p>This gives us a strongly typed collection, which means that every pair of elements we add to it must be of <code>int<\/code> key type and <code>string<\/code> value type. This structure is so similar to a <code>Dictionary<\/code> that we can even initialize a new sorted list by feeding a dictionary into its constructor:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var myDictionary = new Dictionary&lt;int, string&gt; { {1, \"first things first\"}, { 2, \"second things second\" } };\r\nvar myListFromDictionary = new SortedList&lt;int, string&gt;(myDictionary);<\/pre>\n<p>The initialized list will simply sort itself using the keys, and retain the contents of the supplied dictionary. There are four other constructor overloads available when creating a SortedList.<\/p>\n<p>Let&#8217;s describe all the available overloads:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">SortedList&lt;TKey,TValue&gt;(IComparer&lt;TKey&gt;)\r\n\r\nSortedList&lt;TKey,TValue&gt;(IDictionary&lt;TKey,TValue&gt;, IComparer&lt;TKey&gt;)\r\n\r\nSortedList&lt;TKey,TValue&gt;(Int32)\r\n\r\nSortedList&lt;TKey,TValue&gt;(Int32, IComparer&lt;TKey&gt;)<\/pre>\n<p>In whichever overload we use, we can add elements to our list, and expect the list to expand to accommodate the new addition. However, we can&#8217;t add values of any other types to the keys or values. In fact, attempting to do this will give us a syntax error.<\/p>\n<p>Now, let&#8217;s add some elements to our first generic <code>SortedList<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">myList.Add(1, \"This is my first string element\");\r\nmyList.Add(2, \"This is my second string element\");\r\n\r\nmyList.Add(\"three\", \"This is my third string element\"); \/\/ CS1503: Argument 1: cannot convert from 'string' to 'int'\r\nmyList.Add(null, \"There is nothing to see here\"); \/\/ CS1503: Argument 1: cannot convert from '&lt;null&gt;' to 'int'\r\nmyList.Add(5, 5); \/\/ CS1503: Argument 2: cannot convert from 'int' to 'string'<\/pre>\n<p>The last three lines of our code will give us syntax errors because we are trying to insert the wrong types either as a key, or a value. The situation is quite different for a non-generic <code>SortedList<\/code>.<\/p>\n<h3>Non-Generic SortedList<\/h3>\n<p>The non-generic SortedList is available under the <code>System.Collections<\/code> namespace. Here, we don&#8217;t have to declare the types that we will be adding to our collection. Instead, C# uses variable boxing to implicitly determine the acceptable key type once we add our first element to the collection. The value is always boxed and treated as an <code>object<\/code>.<\/p>\n<p>Let&#8217;s create a non-generic <code>SortedList<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var myNonGenericList = new SortedList();<\/code><\/p>\n<p>Once we create an empty <code>SortedList<\/code>, we can use the <code>Add()<\/code> method to insert new elements into the list. Unlike the generic <code>SortedList<\/code>, since the key and value types are evaluated at runtime, we do not get any syntax errors even when we try to add unwanted types to our collection. We will however get runtime exceptions.<\/p>\n<p>Let&#8217;s add the same elements from our generic collection, into this non-generic one:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">myNonGenericList.Add(1, \"This is my first string element\");\r\nmyNonGenericList.Add(2, \"This is my second string element\");\r\n\r\nmyNonGenericList.Add(\"three\", \"This is my third string element\"); \/\/ System.ArgumentException: ...\r\nmyNonGenericList.Add(null, \"There is nothing to see here\"); \/\/ System.ArgumentNullException: ...\r\n\r\n\/\/ This line does not give us any errors!\r\nmyNonGenericList.Add(5, 5);<\/pre>\n<p>Did you notice that the <code><span class=\"enlighter-text\">myNonGenericList.<\/span><span class=\"enlighter-m3\">Add<\/span><span class=\"enlighter-g1\">(<\/span><span class=\"enlighter-n1\">5<\/span><span class=\"enlighter-text\">, <\/span><span class=\"enlighter-n1\">5<\/span><span class=\"enlighter-g1\">)<\/span><\/code><span class=\"enlighter-text\"> line did not return any errors? Since the value is a basic <code>object<\/code> type, our program does not need to control what kind of values we input into our collection. We will have to take responsibility for handling the different types when accessing the <code>SortedList<\/code> within our code.<\/span><\/p>\n<h2>How to Access a SortedList in C#<\/h2>\n<p>There are many methods and properties through which we can access a SortedList. First, let&#8217;s look at the properties of our SortedList:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/sortedList.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-65265\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/sortedList.png\" alt=\"Properties of a SortedList\" width=\"662\" height=\"417\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/sortedList.png 662w, https:\/\/code-maze.com\/wp-content\/uploads\/2022\/02\/sortedList-300x189.png 300w\" sizes=\"auto, (max-width: 662px) 100vw, 662px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The <code>Capacity<\/code> property gives us the maximum number of elements that our SortedList can contain at any moment. The <code>Count<\/code> gives us the number of elements currently within our collection. The <code>Keys<\/code> property gives us a list of all the Keys currently within the collection, while the <code>Values<\/code> property gives us a list of the Values. Under the hood, the SortedList actually makes use of two parallel lists for storing keys and values. The <code>IComparer&lt;T&gt;<\/code> which provides the logic for sorting our collection is also exposed using the <code>Comparer<\/code> property.<\/p>\n<p>There are many methods that we can use to access the SortedList in C#. We have already demonstrated the <code>Add()<\/code> method which adds a new element into the collection with the specified key and value. Once we have elements in the collection, we want to be able to perform actions on the collection. To check if a key is part of a collection, we can use the <code>ContainsKey(TKey)<\/code> method. The <code>IndexOfKey(TKey)<\/code> method will give us the zero-based index of our key if it exists in the list.<\/p>\n<p>Let&#8217;s modify <code>myList<\/code> to add in the 3 and 4 key-value pairs:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">if(!myList.ContainsKey(3))\r\n{\r\n    myList.Add(3, \"This is my third value\");\r\n}\r\n\r\nif(!myList.ContainsValue(\"This is my fourth value\"))\r\n{\r\n    myList.Add(4, \"This is my fourth value\");\r\n}<\/pre>\n<p>For the fourth item, instead of using <code>ContainsKey(TKey)<\/code>, we use <code>ContainsValue(TValue)<\/code>.<\/p>\n<p>When we have the values but not the keys, we can perform the reverse search by using <code>ContainsValue(TValue)<\/code> and <code>IndexOfValue(TValue)<\/code> respectively.<\/p>\n<h2>How to Remove Elements From a SortedList<\/h2>\n<p>While working with our list, we may want to remove some elements from it. Using the <code>RemoveAt(Int32)<\/code> method, we can remove a single element at a zero-based index. If we have the key for this element, we could instead remove it using the <code>Remove(TKey)<\/code> function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">myList.RemoveAt(3) \/\/ removes (2, \"\") which is the item at position 3\r\nmyList.Remove(4) \/\/ removes (4, \"\")\r\n\r\nmyList.Clear() \/\/ removes all the elements and returns an empty collection<\/pre>\n<p>We should remember that in adding or removing elements from a <code>SortedList<\/code>, it must complete a sort operation to make sure the right order is in place.<\/p>\n<h2>When to Use SortedLists<\/h2>\n<p>While SortedList can be a powerful tool for performing quick manipulation of paired data in an orderly manner, there are certain cases where this class may not be suitable.<\/p>\n<p>By its nature, a SortedList must always be sorted. Therefore, whenever we add a new element to the list or remove an element from it, it must sort itself to ensure that all elements are in the right order. This becomes more expensive as we increase the number of elements in our list.<\/p>\n<p>We should only use SortedList when we want to handle smaller collections that need to be sorted at all times. When dealing with larger collections, it is more efficient to use a dictionary, HashSet, or even a regular list which we can then sort once at the point where we need it.<\/p>\n<h2>Conclusion<\/h2>\n<p>The <code>SortedList<\/code> is a very useful and memory-efficient way to store sorted data. It gives us the flexibility of being able to index data, and also select data using keys. Once we have a mastery of the <code>SortedList<\/code> object, we can apply it in so many parts of our daily programming syntax.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys. This data structure guarantees that whenever we add or remove elements from any point in the list, the order of the list will remain the same. In this article, we will [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[505,12],"tags":[946,376,1059],"class_list":["post-64228","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basic","category-csharp","tag-collections","tag-list","tag-sortedlist","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SortedList in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-sortedlist\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SortedList in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-sortedlist\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-09T06:10:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-13T09:50:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"SortedList in C#\",\"datePublished\":\"2022-02-09T06:10:27+00:00\",\"dateModified\":\"2022-07-13T09:50:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/\"},\"wordCount\":1209,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"collections\",\"list\",\"SortedList\"],\"articleSection\":[\"Basic\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-sortedlist\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/\",\"url\":\"https:\/\/code-maze.com\/csharp-sortedlist\/\",\"name\":\"SortedList in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-02-09T06:10:27+00:00\",\"dateModified\":\"2022-07-13T09:50:18+00:00\",\"description\":\"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-sortedlist\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-sortedlist\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SortedList in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SortedList in C# - Code Maze","description":"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-sortedlist\/","og_locale":"en_US","og_type":"article","og_title":"SortedList in C# - Code Maze","og_description":"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.","og_url":"https:\/\/code-maze.com\/csharp-sortedlist\/","og_site_name":"Code Maze","article_published_time":"2022-02-09T06:10:27+00:00","article_modified_time":"2022-07-13T09:50:18+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"SortedList in C#","datePublished":"2022-02-09T06:10:27+00:00","dateModified":"2022-07-13T09:50:18+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/"},"wordCount":1209,"commentCount":2,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["collections","list","SortedList"],"articleSection":["Basic","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-sortedlist\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-sortedlist\/","url":"https:\/\/code-maze.com\/csharp-sortedlist\/","name":"SortedList in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-02-09T06:10:27+00:00","dateModified":"2022-07-13T09:50:18+00:00","description":"A SortedList in C# is a collection of key-value pairs that must be sorted at any given point in time based on its keys.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-sortedlist\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-sortedlist\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"SortedList in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/64228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=64228"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/64228\/revisions"}],"predecessor-version":[{"id":65968,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/64228\/revisions\/65968"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=64228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=64228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=64228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}