C# Eliminating Duplicates in LIST Collection

I have a LIST Collection with 6 columns and I want to remove duplicates based on the column names attributeTtitle.  How can I remove or prevent duplicates based on the attributeTtitle column?  


Logic below writes all attributeTtitles from this collection to EXCEL but there are some duplicates attributeTtitles that need to be removed or ignored.
                foreach (var item in EXCELColummns)
                {
                    Excel.Columns.Add(String.Format("{0}", item.attributeTtitle), Type.GetType("System.String"));
                    //Excel.Columns.Add(String.Format("{0}", item.id), Type.GetType("System.String"));
                }

List<FilteredValuesOfAttribure> EXCELColummns = new List<FilteredValuesOfAttribure>();
 public class FilteredValuesOfAttribure
    {
        public string attributeURL { get; set; }
        public string attributeTtitle { get; set; }
        public string value1 { get; set; }
        public string id { get; set; }
        public string name { get; set; }
        public string SortGroup { get; set; }
    }
tmajor99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi tmajor99;

The following linq query will remove duplicate FilteredValuesOfAttribure object from the List of EXCELColummns.

EXCELColummns = (from fv in EXCELColummns
                 group fv by fv.attributeTtitle into attribGroup
                 select attribGroup.First( )).ToList();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CuteBugCommented:
Another approach is this:
You can make the FilteredValuesOfAttribure class implement IEquatable (Link)
Or,
you can create another class which implements the IEqualityComparer (Link)

In both cases, you can then use the Distinct() method on the List.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.