Q:

Find duplicates in List

Let's say that I have 4 elements in my class: A,B,C and D, which I'm adding to list in my loop. I want to find these elements in my list, which have the same A,B & C values. Now I'm doing sth like this:
List<MyClass> ListMC = new List<MyClass>();

//do something
//read values from file and write them to a,b,c,d

if (ListMC.Any(k => k.A.Equals(a) && k.B.Equals(b) && k.C.Equals(c)))
{
    //write error to another list
    //it won't be add to ListMC
}

Is there any faster way to do this? Because when I'm adding really a lots of elements to ListMC and then it takes a lot of time to check it.
Any ideas? :)
====
Or I can add every time to list this elements (a,b,c,d) and then just remove these duplicates. But I still don't know fast way to do this.

A:

If you don't need the order, use a HashSet instead. It's a lot faster.
So instead use:
HashSet<MyClass> ListMC = new HashSet<MyClass>();

//do something
//read values from file and write them to a,b,c,d

if (ListMC.Any(k => k.A.Equals(a) && k.B.Equals(b) && k.C.Equals(c)))
{
    //write error to another list
    //it won't be add to ListMC
}

If ever you need order, you can convert using ToList(). For example:
List<MyClass> ConvertedToList = ListMC.OrderByDescending(x => x.C).ToList();

