{"id":70467,"date":"2022-05-25T08:00:43","date_gmt":"2022-05-25T06:00:43","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=69862"},"modified":"2022-06-06T11:15:06","modified_gmt":"2022-06-06T09:15:06","slug":"csharp-array-remove-duplicates","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/","title":{"rendered":"Remove Duplicates From a C# Array"},"content":{"rendered":"<p>In this article, we are going to share the different methods on how to remove duplicates from an array in C#. In addition, we are going to compare these methods to check their performance.<\/p>\n<p data-pm-slice=\"1 1 []\">Arrays contain multiple values of the same type. It\u2019s a common occurrence to have some duplicate elements in an array. Although, in some cases, we want the elements to be unique.<\/p>\n<p data-pm-slice=\"1 1 []\">We can achieve this manually or by using some of the .NET inbuilt methods.<\/p>\n<p data-pm-slice=\"1 1 []\"><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-arrays\/RemoveDuplicatesFromAnArray\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div><\/p>\n<p data-pm-slice=\"1 1 []\">Let&#8217;s start.<\/p>\n<h2><a id=\"distinct\"><\/a>Remove Duplicates Using the LINQ Distinct Method<\/h2>\n<p data-pm-slice=\"1 1 []\">To begin with, let\u2019s create <a href=\"https:\/\/code-maze.com\/csharp-basics-arrays\/\" target=\"_blank\" rel=\"noopener\">an array<\/a> containing some duplicate values. We will use this array for all the methods defined:<\/p>\n<p data-pm-slice=\"1 1 []\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">string[] arrayWithDuplicateValues = new string[] { \"Lovely\", \"Lovely\", \"Boy\", \"Boy\" };<\/code><\/p>\n<p>For the duplicate values in our array, we can use the LINQ <code>Distinct()<\/code> method to remove them:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">\/\/ before: {\"Lovely\", \"Lovely\", \"Boy\", \"Boy\" }\r\nvar distinctArray = arrayWithDuplicateValues.Distinct().ToArray(); \/\/ after:  {\"Lovely\", \"Boy\" }<\/pre>\n<p>This is done by invoking the <code>Distinct()<\/code> method on the array. The response is an enumerable object. <code>ToArray()<\/code> converts the response to an array with unique values.<\/p>\n<h2><a id=\"hashing\"><\/a>Remove Duplicates Using HashSet<\/h2>\n<p>HashSet is an unordered collection of a specific type. We can remove duplicates from an array by casting it to a <code>HashSet<\/code> and then converting it back to an array:\u00a0<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var distinctArray = arrayWithDuplicateValues.ToHashSet().ToArray();<\/code><\/p>\n<p>We use <code>ToHashSet()<\/code> on the array to remove the duplicate values. The <code>ToHashSet()<\/code> method returns an enumerable collection. <code>ToArray()<\/code> will alter the response to an array.<\/p>\n<h3>Using the HashSet Constructor<\/h3>\n<p>Similarly, one of the constructors for <code>HashSet<\/code> accepts any collection of values of a particular type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var hashSet = new HashSet&lt;T&gt;(arrayWithDuplicateValues); \r\nvar distinctArray = hashSet.ToArray();<\/pre>\n<p>By default, the compiler will eliminate the duplicate values while constructing the HashSet.<\/p>\n<h2><a id=\"groupby\"><\/a>Remove Duplicates Using LINQ GroupBy and Select Method<\/h2>\n<p>Another way to remove duplicate elements in an array is by combining the <code>GroupBy()<\/code> and <code>Select()<\/code> methods:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var distinctArray = arrayWithDuplicateValues.GroupBy(d =&gt; d).Select(d =&gt; d.First()).ToArray();<\/code><\/p>\n<p>We use <code>GroupBy()<\/code> to organize the elements into groups, and then we select the first item from each of the groups and convert them to an array.\u00a0<\/p>\n<h2><a id=\"looping\"><\/a>Loop Through the Array and Remove Elements Manually<\/h2>\n<p>We can loop through the array and remove the items that occur more than once. We can use the initial array but shift the elements in the array once we hit a duplicate or use a temporary collection to hold the unique elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var size = arrayWithDuplicateValues.Length;\r\n\r\nfor (int i = 0; i &lt; size; i++)\r\n{\r\n    for (int j = i + 1; j &lt; size; j++)\r\n    {\r\n        if (arrayWithDuplicateValues[i] == arrayWithDuplicateValues[j])\r\n        {\r\n            for (int k = j; k &lt; size - 1; k++)\r\n            {\r\n                arrayWithDuplicateValues[k] = arrayWithDuplicateValues[k + 1];\r\n            }\r\n            j--;\r\n            size--;\r\n        }\r\n    }\r\n\r\n}\r\n\r\nvar distinctArray = arrayWithDuplicateValues[0..size]; <\/pre>\n<p data-pm-slice=\"1 1 []\">The if statement in the second loop compares all elements in the array with each other.<\/p>\n<p>Inside the if block, we iterate through the entire array from the duplicate element index and shift the elements to one position left. The order of elements in our array changes during shifting. Once we are done with our iteration, the last element becomes obsolete. Hence, we will reduce the size of the array by 1 and cut it when the iteration is over.<\/p>\n<p>This is far from optimal, but we&#8217;re going to see what the benchmark show at the end.<\/p>\n<h2>Using Swapping Instead of\u00a0 Shifting Elements to Remove Them<\/h2>\n<p>We can use a swapping algorithm instead of the shifting one (the one we previously used) to increase the performance of our code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string[] IterationAndSwappingElements(string[] arrayWithDuplicateValues)\r\n{\r\n    var size = arrayWithDuplicateValues.Length;\r\n\r\n    for (int i = 0; i &lt; size; i++)\r\n    {\r\n        for (int j = i + 1; j &lt; size; j++)\r\n        {\r\n            if (arrayWithDuplicateValues[i] == arrayWithDuplicateValues[j])\r\n            {\r\n                size--;\r\n                arrayWithDuplicateValues[j] = arrayWithDuplicateValues[size];\r\n                j--;\r\n            }\r\n        }\r\n    }\r\n\r\n    return arrayWithDuplicateValues[0..size];\r\n}<\/pre>\n<p>This is a similar code to the previous one, but as you will see in the benchmark a faster one. <strong>Thanks a lot, James Curran for suggesting this (you can read more about it in the comment section).\u00a0<\/strong><\/p>\n<h2>Utilizing the Dictionary Key to Remove Duplicates<\/h2>\n<p>We can also use a dictionary within the for loop to hold the unique elements in our array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var dic = new Dictionary&lt;string, int&gt;();\r\n\r\nforeach (var s in arrayWithDuplicateValues)\r\n{\r\n    dic.TryAdd(s, 1);\r\n}\r\n\r\nvar distinctArray = dic.Select(x =&gt; x.Key.ToString()).ToArray();<\/pre>\n<p>The dictionary keys represent all the unique elements in the array. We&#8217;re utilizing one of the important properties of the Dictionary collection &#8211; all the keys in the dictionary must be unique.<\/p>\n<h3>Improving This Code<\/h3>\n<p>If we just modify the last code line to use the Keys property, we can improve performance:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"10\">public string[] IterationWithDictionaryOpt(string[] arrayWithDuplicateValues)\r\n{\r\n    var dic = new Dictionary&lt;string, int&gt;();\r\n\r\n    foreach (var s in arrayWithDuplicateValues)\r\n    {\r\n        dic.TryAdd(s, 1);\r\n    }\r\n\r\n    return dic.Keys.ToArray();\r\n}<\/pre>\n<p>We add the implementation in a different method so we could compare them in our benchmark test.<\/p>\n<h2>Removing Elements by Using Recursion<\/h2>\n<p>Similarly, we can also construct a recursive method to remove duplicates in an array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string[] RecursiveMethod(string[] arrayWithDuplicateValues, List&lt;string&gt;? mem = default, int index = 0)\r\n{\r\n    if (mem == null)\r\n    {\r\n        mem = new List&lt;string&gt;();\r\n    }\r\n\r\n    if (index &gt;= arrayWithDuplicateValues.Length)\r\n    {\r\n        return arrayWithDuplicateValues;\r\n    }\r\n\r\n    if (mem.IndexOf(arrayWithDuplicateValues[index]) &lt; 0)\r\n    {\r\n        mem.Add(arrayWithDuplicateValues[index]);\r\n    }\r\n\r\n    RecursiveMethod(arrayWithDuplicateValues, mem, index + 1);\r\n\r\n    return mem.ToArray();\r\n}<\/pre>\n<p data-pm-slice=\"1 1 []\">While the function is calling itself, we are using a list to hold all unique values in the array. During this process, we only add values missing to the list. The function stops calling itself when <code>index<\/code> is equal to the length of the array.<\/p>\n<h2><a id=\"performance\"><\/a>Performance Metrics<\/h2>\n<p>Now, we are going to compare the performance of the different methods discussed so far:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|                     Method |        Mean |     Error |    StdDev | Rank |  Gen 0 | Allocated |\r\n|--------------------------- |------------:|----------:|----------:|-----:|-------:|----------:|\r\n|       IterationAndSwapping |    828.1 ns |   2.83 ns |   2.65 ns |    1 | 0.0095 |      40 B |\r\n| IterationWithDictionaryOpt |  2,968.5 ns |   3.71 ns |   2.89 ns |    2 | 0.0648 |     280 B |\r\n|    IterationWithDictionary |  3,051.0 ns |   5.13 ns |   4.55 ns |    3 | 0.0992 |     424 B |\r\n|        ConversionToHashSet |  3,143.7 ns |  17.67 ns |  13.80 ns |    4 | 1.2131 |   5,080 B |\r\n|              HashingMethod |  3,251.4 ns |  11.96 ns |  11.18 ns |    5 | 1.2131 |   5,080 B |\r\n|         DistinctLINQMethod |  3,492.4 ns |  66.41 ns |  62.12 ns |    6 | 1.2283 |   5,144 B |\r\n|            RecursiveMethod |  5,740.9 ns |  22.60 ns |  21.14 ns |    7 | 1.9302 |   8,088 B |\r\n| GroupByAndSelectLINQMethod |  7,188.4 ns |  60.13 ns |  50.21 ns |    8 | 1.1826 |   4,976 B |\r\n|       IterationAndShifting | 18,046.1 ns | 172.29 ns | 152.73 ns |    9 |      - |      40 B |<\/pre>\n<p>The result shows that <code>IterationAndSwapping()<\/code> has a better performance compared to all the other methods based on the average execution time. Also, all the iteration methods\u00a0require less memory compared to the other methods. Based on the average execution time, <code>IterationAndShifting()<\/code> is the worst method by far. Similarly, <code>RecursiveMethod()<\/code> is the worst method based on memory allocation and garbage collection.\u00a0<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>Now not only do we know how to remove duplicate values from an array, but we also know the performance of each method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to share the different methods on how to remove duplicates from an array in C#. In addition, we are going to compare these methods to check their performance. Arrays contain multiple values of the same type. It\u2019s a common occurrence to have some duplicate elements in an array. Although, [&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":[1057,12],"tags":[1043,946,1261],"class_list":["post-70467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-array","category-csharp","tag-array","tag-collections","tag-duplicate","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>Remove Duplicates From a C# Array - Code Maze<\/title>\n<meta name=\"description\" content=\"Let&#039;s learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...\" \/>\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-array-remove-duplicates\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remove Duplicates From a C# Array - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Let&#039;s learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-25T06:00:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-06T09:15:06+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=\"6 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-array-remove-duplicates\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Remove Duplicates From a C# Array\",\"datePublished\":\"2022-05-25T06:00:43+00:00\",\"dateModified\":\"2022-06-06T09:15:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\"},\"wordCount\":784,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"Array\",\"collections\",\"Duplicate\"],\"articleSection\":[\"Array\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\",\"url\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\",\"name\":\"Remove Duplicates From a C# Array - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-05-25T06:00:43+00:00\",\"dateModified\":\"2022-06-06T09:15:06+00:00\",\"description\":\"Let's learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#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-array-remove-duplicates\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Remove Duplicates From a C# Array\"}]},{\"@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":"Remove Duplicates From a C# Array - Code Maze","description":"Let's learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...","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-array-remove-duplicates\/","og_locale":"en_US","og_type":"article","og_title":"Remove Duplicates From a C# Array - Code Maze","og_description":"Let's learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...","og_url":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/","og_site_name":"Code Maze","article_published_time":"2022-05-25T06:00:43+00:00","article_modified_time":"2022-06-06T09:15:06+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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Remove Duplicates From a C# Array","datePublished":"2022-05-25T06:00:43+00:00","dateModified":"2022-06-06T09:15:06+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/"},"wordCount":784,"commentCount":7,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["Array","collections","Duplicate"],"articleSection":["Array","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/","url":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/","name":"Remove Duplicates From a C# Array - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-05-25T06:00:43+00:00","dateModified":"2022-06-06T09:15:06+00:00","description":"Let's learn how to remove duplicates from a C# array using various methods, including LINQ, HashSet, Dictionary, recursive, manual removal...","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-array-remove-duplicates\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-array-remove-duplicates\/#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-array-remove-duplicates\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Remove Duplicates From a C# Array"}]},{"@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\/70467","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=70467"}],"version-history":[{"count":7,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70467\/revisions"}],"predecessor-version":[{"id":71106,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/70467\/revisions\/71106"}],"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=70467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=70467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=70467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}