{"id":76557,"date":"2022-11-09T08:00:45","date_gmt":"2022-11-09T07:00:45","guid":{"rendered":"https:\/\/code-maze.com\/?p=76557"},"modified":"2023-06-15T14:59:17","modified_gmt":"2023-06-15T12:59:17","slug":"csharp-sortedset","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-sortedset\/","title":{"rendered":"SortedSet in C#"},"content":{"rendered":"<p>A SortedSet in C# is a data structure that allows us to store and access elements in sorted order. In this article, we are going to explore how to create and use the SortedSet class\u00a0in C#. We are also going to look at some of the benefits and drawbacks of using this data structure.<\/p>\n<p>Finally, the article concludes with tips on taking advantage of the C# SortedSet in our 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\/SortedSetInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Without further ado, let&#8217;s begin!<\/p>\n<h2><strong><a id=\"what\"><\/a>What Is a SortedSet in C#<\/strong>?<\/h2>\n<p>A <code>SortedSet<\/code> in C# is a collection of unique elements sorted according to their natural ordering or a specified comparator. It allows for fast retrieval of elements and efficient operations on subsets.<\/p>\n<p>The <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.collections.generic.sortedset-1?view=net-7.0\" target=\"_blank\" rel=\"nofollow noopener\">SortedSet&lt;T&gt;<\/a> class has been available since .NET as part of the <code>System.Collection.Generic<\/code> namespace.<\/p>\n<p>One notable feature of the <code>SortedSet<\/code> is its ability to efficiently perform set operations such as union, intersection, and difference, which makes it <strong>particularly useful for tasks such as creating a list of unique elements from multiple sets.<\/strong><\/p>\n<p><code>SortedSet<\/code> <strong>does not allow null values or permit duplicate elements<\/strong>. Trying to add a duplicate element will not affect the set.\u00a0<\/p>\n<h2><a id=\"how\"><\/a>How to Create a SortedSet in C#?<\/h2>\n<p>For most of our examples, we intend to use a <code>SortedSet<\/code> that contains strings of some of the programming languages used today.<\/p>\n<p>Let&#8217;s start by creating an empty <code>SortedSet<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var languages = new SortedSet&lt;string&gt;();<\/code><\/p>\n<h2><a id=\"overloads\"><\/a>SortedSet Constructor Overloads<\/h2>\n<p>We can use these overloads when working with the <code>SortedSet<\/code> class\u00a0in C#:<\/p>\n\n<table id=\"tablepress-66\" class=\"tablepress tablepress-id-66\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Overload<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">SortedSet()<\/td><td class=\"column-2\">We use it to initialize a new instance of the SortedSet class.<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">SortedSet(IComparer)<\/td><td class=\"column-2\">Initializes a new  SortedSet instance along with a comparer.<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">SortedSet(IEnumerable)<\/td><td class=\"column-2\">This overload initializes a new SortedSet instance from elements copied from a specific enumerable collection.<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">SortedSet(IEnumerable, IComparer)<\/td><td class=\"column-2\">Creates a new instance of a SortedSet which has elements from an enumerable collection and that uses a specific comparer.<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">SortedSet(SerializationInfo, StreamingContext)<\/td><td class=\"column-2\">Initializes a SortedSet instance that contains serialized elements.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-66 from cache -->\n<p>To make our article as simple as possible, we are going to implement the first overload, <code>SortedSet()<\/code> and learn how it works.\u00a0<\/p>\n<h2><a id=\"add\"><\/a>Add Items to a SortedSet<\/h2>\n<p>Let&#8217;s add a set of programming languages into a <code>SortedSet&lt;string&gt;<\/code> object:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public SortedSet&lt;string&gt; ProgrammingLanguages() \r\n{ \r\n    var languages = new SortedSet&lt;string&gt;(); \r\n\r\n    languages.Add(\"C\"); \r\n    languages.Add(\"C++\"); \r\n    languages.Add(\"C#\"); \r\n    languages.Add(\"Java\"); \r\n    languages.Add(\"Scala\"); \r\n    languages.Add(\"TypeScript\"); \r\n    languages.Add(\"Python\"); \r\n    languages.Add(\"JavaScript\"); \r\n    languages.Add(\"Rust\");\r\n    \r\n    return languages;\r\n}<\/pre>\n<p>Here, we insert elements into the <code>languages<\/code> SortedSet by invoking the <code>Add()<\/code> method.<\/p>\n<p>In some cases, we may want to initialize a\u00a0 <code>SortedSet<\/code>\u00a0directly with values:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var languages = new SortedSet&lt;string&gt; { \"C\", \"C++\", \"C#\", \"Java\" };<\/code><\/p>\n<p>Let&#8217;s initialize our <code>SortedSet<\/code> in the test constructor:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private readonly SortedSetMethods _sortedSet; \r\nprivate readonly SortedSet&lt;string&gt; _languages;\r\n\r\npublic SortedSetInCSharpUnitTests()\r\n{\r\n    _sortedSet = new SortedSetMethods();\r\n    _languages = _sortedSet.ProgrammingLanguages();\r\n}<\/pre>\n<p>Next, we can verify that our <code>SortedSet<\/code> has <strong>nine elements<\/strong> and check whether it <strong>contains one of the elements (&#8220;Java&#8221;) and the first element is (&#8220;C&#8221;)<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Assert.IsInstanceOfType(_languages, typeof(SortedSet&lt;string&gt;));\r\nAssert.AreEqual(_languages.Count(), 9);\r\nAssert.IsTrue(_languages.Contains(\"Java\"));\r\nAssert.AreEqual(_languages.First(), \"C\");<\/pre>\n<p>We can successfully prove that <code>_languages<\/code> is of type <code>SortedSet&lt;string&gt;<\/code>. We use the inbuilt <code>Count()<\/code> method to check the number of elements in our SortedSet.<\/p>\n<p>Also, we use the inbuilt <code>Contains()<\/code> method to check if the <code>SortedSet<\/code> has a specific element. The method takes the element as a parameter and returns a boolean value indicating whether or not the element is present in the set.<\/p>\n<p>This technique can be helpful for quickly checking if an element exists in the <code>SortedSet<\/code> without iterating through all of the elements.<\/p>\n<h2><strong><a id=\"duplicates\"><\/a>Add Duplicate Elements in a SortedSet in C#<\/strong><\/h2>\n<p>A <code>SortedSet<\/code> does not allow adding duplicate elements. It will not affect the set if we try to add a duplicate element. It uses a hashing structure that ensures that each element can only appear once in the set.<\/p>\n<p>Let&#8217;s attempt to add duplicate elements to the <code>_languages<\/code> <code>SortedSet<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">_languages.Add(\"C\");\r\n_languages.Add(\"C++\");\r\n_languages.Add(\"C#\");\r\n\r\nAssert.IsInstanceOfType(_languages, typeof(SortedSet&lt;string&gt;));\r\nAssert.AreEqual(_languages.Count(), 9);<\/pre>\n<p>When we try to add duplicate values to <code>_languages<\/code>, its values will not change, as the set already contains those values. Therefore, its count remains nine instead of twelve.<\/p>\n<h2><a id=\"object-sorting\"><\/a>How Does a SortedSet Deal With Object Sorting?<\/h2>\n<p>To achieve object sorting in a <code>SortedSet&lt;T&gt;<\/code> object, the <code>SortedSet&lt;T&gt;<\/code> class has a <code>SortedSet&lt;T&gt;.Comparer<\/code> property that ensures all the elements in the object are in the correct order. The property implements the <a href=\"https:\/\/code-maze.com\/csharp-icomparable-icomparer-comparison-delegate\/\" target=\"_blank\" rel=\"noopener\">IComparer&lt;T&gt;<\/a> interface, which compares elements and ensures that the <code>SortedSet&lt;T&gt;<\/code> elements are in the correct order.\u00a0<\/p>\n<p>In our case, the <code>SortedSet&lt;T&gt;<\/code> class uses the default comparer to ensure that we store our programming languages in the correct order.<\/p>\n<h2><a id=\"iterate\"><\/a>Iterate Through a SortedSet in C#<\/h2>\n<p>We can iterate through a <code>SortedSet<\/code> object by using a <code>foreach<\/code> or a <code>for<\/code> loop statement.<\/p>\n<p>Let&#8217;s invoke the <code>languages<\/code> SortedSet in our main program and iterate through it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var sortedSet = new SortedSetMethods();\r\nvar programmingLanguages = sortedSet.ProgrammingLanguages();\r\n\r\nConsole.WriteLine(\"The SortedSet Contains these elements:\");\r\n\r\nforeach (var language in programmingLanguages) \r\n{\r\n    Console.WriteLine(language);\r\n}<\/pre>\n<p>After executing the program, we can see that our programming languages are in the correct alphabetic order:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">The SortedSet Contains these elements:\r\nC\r\nC#\r\nC++\r\nJava\r\nJavaScript\r\nPython\r\nRust\r\nScala\r\nTypeScript\r\n<\/pre>\n<h2><a id=\"clear\"><\/a>Remove All Elements From a SortedSet in C#<\/h2>\n<p>What if we want to remove all the elements in a <code>SortedSet<\/code>? We can make use of the <code>Clear()<\/code> inbuilt method.<\/p>\n<p>Let&#8217;s verify that the <code>Clear()<\/code> method removes all elements from the <code>_languages<\/code> set:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">_languages.Clear();\r\n\r\nAssert.AreEqual(0, _languages.Count());\r\nAssert.IsNull(_languages.FirstOrDefault());<\/pre>\n<p>After invoking the <code>Clear()<\/code> method, we can prove that we removed all the elements from the <code>_languages<\/code> set as it has a count of zero.\u00a0\u00a0<\/p>\n<h2><a id=\"copy\"><\/a>Copy SortedSet Elements to an Array<\/h2>\n<p>The <code>CopyTo()<\/code> method copies a part of or the entire <code>SortedSet<\/code> into a <a href=\"https:\/\/code-maze.com\/csharp-basics-arrays\/\" target=\"_blank\" rel=\"noopener\">one-dimensional array<\/a> of the same type. The method has some <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.collections.generic.sortedset-1.copyto?view=net-7.0\" target=\"_blank\" rel=\"nofollow noopener\">overloads<\/a>, which give us an option of copying elements at the beginning of the destination array or from a specific index.<\/p>\n<p>To keep our example simple, let&#8217;s copy all the elements in the <code>_languages<\/code> SortedSet into an array by taking advantage of the <code>CopyTo()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var languagesArray = new string[9];\r\n\r\n_languages.CopyTo(languagesArray);\r\n\r\nAssert.AreEqual(languagesArray.Count(), 9);\r\nAssert.AreEqual(languagesArray[0], \"C\");\r\nAssert.AreEqual(languagesArray[8], \"TypeScript\");\r\nAssert.IsNotNull(languagesArray);<\/pre>\n<p>Alternatively, we can convert a <code>SortedSet<\/code> into an array by invoking the <code>ToArray()<\/code> method:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var languagesArray = _languages.ToArray();<\/code><\/p>\n<h2><a id=\"except-with\"><\/a>Perform Set Difference Between Two SortedSets in C#<\/h2>\n<p>This operation performs a set difference operation between two sets. If we perform a set difference between sets A and B, the operation returns the elements in A that are not present in B.<\/p>\n<p>Let&#8217;s understand this concept with another example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; { \"C\", \"C++\", \"C#\", \"Java\", \"Scala\", \"Assembly\", \r\n                    \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\n\r\n_languages.ExceptWith(moreLanguages);\r\n\r\nAssert.AreEqual(_languages.Count(), 4);\r\nAssert.IsTrue(_languages.Contains(\"TypeScript\"));\r\nAssert.IsTrue(_languages.Contains(\"Python\"));\r\nAssert.IsTrue(_languages.Contains(\"JavaScript\"));\r\nAssert.IsTrue(_languages.Contains(\"Rust\"));\r\nAssert.IsFalse(_languages.Contains(\"Assembly\"));<\/pre>\n<p>The <code>ExceptWith()<\/code> method returns the elements that are in <code>_languages<\/code> but not in <code>moreLanguages<\/code>, which are: &#8220;TypeScript&#8221;, &#8220;Python&#8221;, &#8220;JavaScript&#8221; and &#8220;Rust&#8221;.\u00a0<\/p>\n<h2><a id=\"intersect-with\"><\/a>Find Common Elements Between Two SortedSets<\/h2>\n<p>An intersection between sets A and B entails finding the common elements. To accomplish such an operation in C#, we use the inbuilt <code>IntersetWith()<\/code> method.\u00a0<\/p>\n<p>Let&#8217;s understand how to perform an intersection operation with an example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; { \"C\", \"C++\", \"C#\", \"Java\", \"Scala\", \"Assembly\", \r\n                    \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\n\r\n_languages.IntersectWith(moreLanguages);\r\n\r\nAssert.AreEqual(_languages.Count(), 5);\r\nAssert.IsTrue(_languages.Contains(\"C\"));\r\nAssert.IsTrue(_languages.Contains(\"C++\"));\r\nAssert.IsTrue(_languages.Contains(\"C#\"));\r\nAssert.IsTrue(_languages.Contains(\"Java\"));\r\nAssert.IsTrue(_languages.Contains(\"Scala\"));\r\nAssert.IsFalse(_languages.Contains(\"Assembly\"));<\/pre>\n<p>Here, the <code>IntersectWith()<\/code> method modifies the <code>_languages<\/code> SortedSet by retaining the elements that are common in both <code>_languages<\/code> and <code>moreLanguages<\/code> sets.\u00a0<\/p>\n<h2><a id=\"proper-subset\"><\/a>How to Check A SortedSet Is a Subset of Another<\/h2>\n<p>When we want to check whether a <code>SortedSet<\/code> instance is a proper subset of another <code>SortedSet<\/code> instance, we use the <code>IsProperSubsetOf()<\/code> method. Likewise, we can use the <code>IsProperSupersetOf()<\/code> method to determine if a <code>SortedSet<\/code> is a superset of another <code>SortedSet<\/code>.<\/p>\n<p>Let&#8217;s put this theory into practice:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; {\"C\", \"C++\", \"C#\", \"Java\", \"Scala\", \"TypeScript\", \r\n                    \"Python\", \"JavaScript\", \"Rust\", \"Assembly\", \"Pascal\"};\r\n\r\nAssert.IsTrue(_languages.IsSubsetOf(moreLanguages));\r\nAssert.IsTrue(_languages.IsProperSubsetOf(moreLanguages));\r\nAssert.IsTrue(moreLanguages.IsSupersetOf(_languages));\r\nAssert.IsTrue(moreLanguages.IsProperSupersetOf(_languages));<\/pre>\n<p>We create a larger set <code>moreLanguages<\/code> that contains more elements, including all the elements in the <code>_languages<\/code> set. Therefore, <code>_languages<\/code> is a proper subset of <code>moreLanguages<\/code> and the latter is the proper superset of the former.\u00a0<\/p>\n<p><strong>So, what&#8217;s the difference between a proper subset and a normal one?\u00a0<\/strong><\/p>\n<p>In set theory, a subset is a collection of elements within another set. A proper subset, also known as a strictly smaller subset, is a subset that contains strictly fewer elements than the larger set.\u00a0<br \/>\nA proper subset will always have fewer elements than the larger set, which may not be true for a subset. For example, if we have the set <code>A = {1, 2, 3}<\/code>, <code>B = {1, 2}<\/code> is a proper subset because it contains strictly fewer elements than A. On the other hand, <code>C = {1, 2, 3}<\/code> would not be considered a proper subset because it has the same number of elements as A.<\/p>\n<h2><a id=\"overlaps\"><\/a>Determine Whether Two SortedSets Overlap<\/h2>\n<p>In some situations, we may want to check whether two <code>SortedSet<\/code> objects\u00a0share common elements without evaluating whether they are <a href=\"#set-equals\">equal<\/a>. That&#8217;s where we can take advantage of the <code>Overlaps()<\/code> method to achieve our objective:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var commonLanguages = new SortedSet&lt;string&gt; { \"C\", \"C++\", \"C#\", \"Java\", \"Scala\", \"TypeScript\", \r\n                      \"Python\", \"JavaScript\", \"Rust\", \"Assembly\", \"Pascal\" };\r\nvar differentLanguages = new SortedSet&lt;string&gt; { \"Assembly\", \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\n\r\nAssert.IsTrue(commonLanguages.Overlaps(_languages));\r\nAssert.IsTrue(differentLanguages.Overlaps(commonLanguages));\r\nAssert.IsFalse(differentLanguages.Overlaps(_languages));<\/pre>\n<p>We can see that the <code>commonLanguages<\/code> and <code>_languages<\/code> SortedSets have common elements. The same case applies to <code>differentLanguages<\/code> and <code>commonLanguages<\/code>. However, <code>differentLanguages<\/code> and <code>languages<\/code> do not have overlapping elements.\u00a0<\/p>\n<h2><a id=\"remove\"><\/a>Remove a Particular Element From a SortedSet<\/h2>\n<p>To remove an item from the <code>SortedSet<\/code>, we can use the <code>Remove()<\/code> method. Like the <a href=\"#add\">Add()<\/a> method, it takes the object as a parameter and removes it from the <code>SortedSet<\/code>.<\/p>\n<p>Let&#8217;s put our knowledge into practice:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public SortedSet&lt;string&gt; RemoveElement(SortedSet&lt;string&gt; sortedSet, string valueToRemove) \r\n{\r\n    _sortedSet.Remove(valueToRemove);\r\n\r\n    return sortedSet;\r\n}<\/pre>\n<p>Here, the <code>RemoveElement()<\/code> method takes a <code>SortedSet&lt;string&gt;<\/code> and a <code>string<\/code> as parameters and uses the <code>Remove()<\/code> method to remove an element before returning the updated <code>SortedSet<\/code>.\u00a0<\/p>\n<p>Next, we can verify that our new method successfully removes elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var elementToRemove = \"Java\";\r\n\r\nvar updatedLanguages = _sortedSet.RemoveElement(_languages, elementToRemove);\r\n\r\nAssert.IsFalse(updatedLanguages.Contains(elementToRemove));\r\nAssert.AreEqual(_languages.Count(), 8);<\/pre>\n<p>We invoke the <code>RemoveElement()<\/code> method and pass our <code>SortedSet<\/code>, and a string (&#8220;Java&#8221;), which we can prove is removed as the updated <code>SortedSet<\/code> does not contain that value, and its count decreases by one.\u00a0<\/p>\n<h2><a id=\"remove-where\"><\/a>Remove Elements From a SortedSet Through Predicates<\/h2>\n<p>Besides using the inbuilt <code>Remove()<\/code> method, we can use the <code>RemoveWhere()<\/code> method that takes a <a href=\"https:\/\/code-maze.com\/delegates-charp\/\" target=\"_blank\" rel=\"noopener\">predicate<\/a> as a parameter to set conditions that determine whether we remove an element. To illustrate this concept, let&#8217;s modify our <code>_languages<\/code> SortedSet to remove programming languages that start with a specific character:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">_languages.RemoveWhere(element =&gt; element.StartsWith(\"C\"));\r\nAssert.IsFalse(_languages.Contains(\"C\"));\r\nAssert.IsFalse(_languages.Contains(\"C++\"));\r\nAssert.IsFalse(_languages.Contains(\"C#\"));<\/pre>\n<p>We can verify that the <code>RemoveWhere()<\/code> method removes all elements starting with the letter &#8216;C.&#8217;<\/p>\n<h2><a id=\"reverse\"><\/a>Reverse Elements of a SortedSet in C#<\/h2>\n<p>In some cases, we may want to reverse the order of the elements we have in a <code>SortedSet<\/code>. We can take advantage of the inbuilt <code>Reverse()<\/code> method to achieve our goal. The method returns an <a href=\"https:\/\/code-maze.com\/dotnet-collections-ienumerable-iqueryable-icollection\/\" target=\"_blank\" rel=\"noopener\">IEnumerable&lt;T&gt;<\/a> object, which iterates over the <code>SortedSet<\/code> in reverse order.\u00a0<\/p>\n<p>Let&#8217;s illustrate how the <code>Reverse()<\/code> method works:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var reversedSet = _languages.Reverse();\r\nvar firstElement = reversedSet.First();\r\nvar lastElement = reversedSet.Last();\r\n\r\nAssert.IsInstanceOfType(reversedSet, typeof(IEnumerable&lt;string&gt;));\r\nAssert.AreEqual(firstElement, \"TypeScript\");\r\nAssert.AreEqual(lastElement, \"C\");<\/pre>\n<p>We can prove that we get an <code>IEnumerable&lt;string&gt;<\/code> object, which iterates over the <code>_languages<\/code> SortedSet in reverse order.\u00a0<\/p>\n<h2><a id=\"set-equals\"><\/a>How to Check if Two SortedSets Are Equal in C#<\/h2>\n<p>In some cases, we may want to compare whether the current <code>SortedSet<\/code> and another collection contain the same elements. We can use the <code>SetEquals()<\/code> method to achieve our goal:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; { \"Assembly\", \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\nvar languagesCopy = _languages;\r\n\r\nAssert.IsFalse(_languages.SetEquals(moreLanguages));\r\nAssert.IsTrue(_languages.SetEquals(languagesCopy));<\/pre>\n<p>The <code>moreLanguages<\/code> object is not equal to the <code>_languages<\/code> object, so we expect the <code>SetEquals()<\/code> operation to return <code>false<\/code>.<\/p>\n<div style=\"padding: 20px; border-left: 5px gray solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">Note<strong> this method ignores the order of elements<\/strong> <strong>and any duplicates<\/strong> in the other collection compared to the current <code>SortedSet<\/code>.\u00a0<\/div>\n<h2><a id=\"symmetric-except-with\"><\/a>Store Unique Elements From Two SortedSets<\/h2>\n<p>Sometimes, we may want to modify a <code>SortedSet<\/code> to store unique elements between two sets. That&#8217;s where the <code>SymmetricExceptWith()<\/code> method comes into play, as we can use it to accomplish our purpose.<\/p>\n<p>Let&#8217;s look at using the <code>SymmetricExceptWith()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; { \"Assembly\", \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\n\r\n_languages.SymmetricExceptWith(moreLanguages);\r\n\r\nAssert.AreEqual(_languages.Count(), 14);<\/pre>\n<p>The <code>SymmetricExceptWith()<\/code> method modifies the <code>_languages<\/code> SortedSet to make it have unique elements from both itself and <code>moreLanguages<\/code> SortedSet. Therefore, since both sets have unique values, the modified <code>_languages<\/code> SortedSet now contains fourteen elements.\u00a0<\/p>\n<h2><a id=\"try-get-value\"><\/a>How to Search for an Element in a SortedSet in C#<\/h2>\n<p>Besides using the inbuilt <code>Contains()<\/code> method to check whether a <code>SortedSet<\/code> contains a specific value, we can use the inbuilt <code>TryGetValue (T equalVal, out T actualVal)<\/code> technique to achieve the same result. The method takes two parameters, the first being the value to search for and the next being what the search finds or the default value when the search doesn&#8217;t yield any results.\u00a0<\/p>\n<p>Let&#8217;s put this theory into practice:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Assert.IsTrue(_languages.TryGetValue(\"C#\", out _));\r\nAssert.IsTrue(_languages.Contains(\"C#\"));\r\nAssert.IsFalse(_languages.TryGetValue(\"Assembly\", out _));\r\nAssert.IsFalse(_languages.Contains(\"Assembly\"));<\/pre>\n<p>Here, <code>_languages<\/code> does not contain &#8220;Assembly&#8221; but contains &#8220;C#&#8221; and uses the discard operator to ignore the <code>TryGetValue()<\/code> method&#8217;s return value.\u00a0\u00a0<\/p>\n<h2><a id=\"union-with\"><\/a>Perform a Union Between Two SortedSets<\/h2>\n<p>When we want to join two sets, we perform a union operation. For example, when we want to perform a union between two sets, A and B, we copy the elements in set B over into set A.\u00a0<\/p>\n<p>Let&#8217;s perform a <code>UnionWith()<\/code> operation between <code>_languages<\/code> and <code>moreLanguages<\/code> SortedSet to illustrate this concept:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var moreLanguages = new SortedSet&lt;string&gt; { \"Assembly\", \"Pascal\", \"HTML\", \"CSS\", \"PHP\" };\r\n\r\n_languages.UnionWith(moreLanguages);\r\nAssert.AreEqual(_languages.Count(), 14);<\/pre>\n<p>The <code>UnionWith()<\/code> method copies the elements in <code>moreLanguages<\/code> SortedSet into the <code>_languages<\/code> SortedSet hence, the latter now has fourteen elements instead of nine.\u00a0<\/p>\n<h2><a id=\"benefits\"><\/a>Benefits of Using a SortedSet in C#<\/h2>\n<p>First, <code>SortedSet<\/code> objects\u00a0facilitate quick insertion and retrieval operations as <strong>they have a constant access time of O(1).<\/strong><\/p>\n<p>Also, we can use the <code>SortedSet<\/code> class\u00a0in applications that <strong>do not allow duplicate elements<\/strong>, which helps us eliminate data redundancy.<\/p>\n<p>A <code>SortedSet<\/code> can quickly check<strong>\u00a0if an element is present in the set without iterating<\/strong> through all elements and <strong>returns elements in a specific order<\/strong>.\u00a0<\/p>\n<p>Overall, a <code>SortedSet<\/code> in C# can significantly aid in managing and manipulating sorted collections of unique elements.<\/p>\n<h2><a id=\"drawbacks\"><\/a>Drawbacks of Using a SortedSet in C#<\/h2>\n<p>Using the <code>SortedSet<\/code> may not be suitable for all situations where we need to <strong>store null values or duplicate elements<\/strong>.<\/p>\n<p>Additionally, the performance benefits of using a <code>SortedSet<\/code> may not be significant in small collections.<\/p>\n<p>In some cases, accessing and manipulating elements by their index may also be necessary rather than simply iterating through them in sorted order. Another collection type, such as a <a href=\"https:\/\/code-maze.com\/csharp-list-collection\/\" target=\"_blank\" rel=\"noopener\">list<\/a>, may be more appropriate in such cases.<\/p>\n<p>Overall, it is crucial to carefully evaluate whether the restrictions and advantages of using a <code>SortedSet<\/code> are suitable for a given situation before implementing it in C# code.<\/p>\n<h2><a id=\"sets-vs-lists\"><\/a>SortedSets vs SortedLists<\/h2>\n<p>One similarity between a <code>SortedSet<\/code> and a <a href=\"https:\/\/code-maze.com\/csharp-sortedlist\/\" target=\"_blank\" rel=\"noopener\">SortedList<\/a> in C# is that <strong>both data structures maintain their elements in sorted order<\/strong>.\u00a0However, a <code>SortedSet<\/code> does not allow duplicate elements, unlike a SortedList. In addition, a <code>SortedSet<\/code> has faster insertion and removal times than a SortedList, <strong>as the latter internally uses an array structure<\/strong>, which requires shifting elements around during insertion and removal.<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>SortedSet in C# provides a valuable tool for managing and manipulating sorted collections of unique elements. However, it is essential to carefully consider whether its restrictions and advantages make it suitable for a specific situation before implementing it in code. If you enjoyed this article, feel free to check out our article on a similar topic, <a href=\"https:\/\/code-maze.com\/csharp-hashset\/\" target=\"_blank\" rel=\"noopener\">HashSet in C#<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A SortedSet in C# is a data structure that allows us to store and access elements in sorted order. In this article, we are going to explore how to create and use the SortedSet class\u00a0in C#. We are also going to look at some of the benefits and drawbacks of using this data structure. Finally, [&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":[12],"tags":[1487],"class_list":["post-76557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-sortedset","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>SortedSet in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.\" \/>\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-sortedset\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SortedSet in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-sortedset\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-09T07:00:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-15T12:59:17+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=\"11 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-sortedset\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"SortedSet in C#\",\"datePublished\":\"2022-11-09T07:00:45+00:00\",\"dateModified\":\"2023-06-15T12:59:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/\"},\"wordCount\":2041,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"sortedset\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-sortedset\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/\",\"url\":\"https:\/\/code-maze.com\/csharp-sortedset\/\",\"name\":\"SortedSet in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-11-09T07:00:45+00:00\",\"dateModified\":\"2023-06-15T12:59:17+00:00\",\"description\":\"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-sortedset\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-sortedset\/#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-sortedset\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SortedSet 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":"SortedSet in C# - Code Maze","description":"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.","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-sortedset\/","og_locale":"en_US","og_type":"article","og_title":"SortedSet in C# - Code Maze","og_description":"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.","og_url":"https:\/\/code-maze.com\/csharp-sortedset\/","og_site_name":"Code Maze","article_published_time":"2022-11-09T07:00:45+00:00","article_modified_time":"2023-06-15T12:59:17+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":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-sortedset\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"SortedSet in C#","datePublished":"2022-11-09T07:00:45+00:00","dateModified":"2023-06-15T12:59:17+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/"},"wordCount":2041,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["sortedset"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-sortedset\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-sortedset\/","url":"https:\/\/code-maze.com\/csharp-sortedset\/","name":"SortedSet in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-11-09T07:00:45+00:00","dateModified":"2023-06-15T12:59:17+00:00","description":"In this article, we are going to look at the SortedSet collection in C#, along with some of the methods for manipulating sets.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-sortedset\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-sortedset\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-sortedset\/#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-sortedset\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"SortedSet 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\/76557","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=76557"}],"version-history":[{"count":7,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/76557\/revisions"}],"predecessor-version":[{"id":91690,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/76557\/revisions\/91690"}],"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=76557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=76557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=76557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}