1

I have an ArrayList of email addresses. I want to remove duplicates from it.

For example my array list is:

  • abc@gmail.com
  • xyz@gmail.com
  • abc@yahoo.com
  • asd@yahoo.com

I want output like this

  • abc@gmail.com
  • abc@yahoo.com
Aristos
  • 66,005
  • 16
  • 114
  • 150
NKS
  • 25
  • 8

1 Answers1

2

Something like this:

ArrayList arr = new ArrayList { "abc@gmail.com", "xyz@gmail.com", 
                                     "abc@yahoo.com", "asd@yahoo.com" };

var res = arr.ToArray().GroupBy(c => c.ToString().Split('@')[1])
                       .Select(c=> c.FirstOrDefault()).ToArray();

I used an ArrayList to adjust with your question, but it would be better to use a List or Array of string instead.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109