---
title: "Remove duplicates from array"  
description: "Remove duplicates from array"  
author: "Anonymous User"  
published: 2013-02-16  
updated: 2013-02-18  
canonical: https://www.mindstick.com/forum/610/remove-duplicates-from-array  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Remove duplicates from array

Hi Everyone!

I have been working with a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)[] [array in C#](https://www.mindstick.com/forum/222/how-do-i-set-negative-number-to-index-of-array-in-c-sharp) that gets returned from a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) call. I was wondering what the best way to [remove duplicates](https://www.mindstick.com/forum/160918/help-with-writing-a-query-to-remove-duplicates-from-a-table-in-sql-server) from this

array would be? I could possibly [cast](https://answers.mindstick.com/qa/97273/how-to-cast-a-baitcaster) to a Generic [collection](https://www.mindstick.com/articles/1718/collections-in-java), but I was wondering if there was a better way to do it, possibly by using a temp array?

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ankit!\
You could try this way!\
int[] nAs = { 1, 2, 3, 3, 4}; int[] nQ = nAs.Distinct().ToArray();

### Reply by Shankar M

Hi Ankit,\
You can [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) Duplicates by using a HashSet.

```
string[] names = {"Windows", "Oracle", "Windows", "Csharp", "Oracle", "Windows", "Telnet", "Oracle", "Csharp" };            var AlteredSet = new HashSet<string>(names);            foreach (string str in AlteredSet)            {                MessageBox.Show(str);            }
```

\
Regards,Shankar\
\


---

Original Source: https://www.mindstick.com/forum/610/remove-duplicates-from-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
