How to Duplicate Values from an ArrayList

3

I would like to know how I can separate values that show duplicity, an example:

I have a% Variable with% set to FormaPagto ,

In this variable I have 6 data:

  

0 - Money 1 - Debt 2 - Debt 3 - Money 4 - Money 5 -   Check

What I want to do, separate the distinct values, in case I get only the values without them repeating, would look like this:

  

0 - Money 1 - Debt 2 - Check

Grouping the values leaving them unique, and if possible leave them in a ArrayList .

Is there any function of ArrayList itself that does such magic? Or what do they suggest?

    
asked by anonymous 28.05.2015 / 15:42

1 answer

3

First, you should not use ArrayList . Since the generic in C # 2.0, it is recommended to use List<T> generic.

With a List<T> , you can use the extension Enumerable.Distinct to remove duplicate values.

using System.Linq;
using System.Collections.Generic;

var list = new List<String> {"Dinheiro", "Debito", "Debito", "Dinheiro", "Cheque"};
var distinct = list.Distinct().ToList();
    
28.05.2015 / 15:50