Question: I have an array of Customer[] objects, and I want to use it to create a Dictionary<Customer, string>. What is the easiest way to examine the array for duplicates before I load the Dictionary? I want to avoid "ArgumentException: An item with the same key has already been added". Thanks.

Answer: 
You could use LINQ to do both:

```
Customer[] customers; // initialized somehow...
var customerDictionary = customers.Distinct().ToDictionary( cust => cust.SomeKey );

```

If you will build the dictionary in a less straightforward fashion, you can just use the `Distinct()` extension method to get a unique array like so:

```
Customer[] uniqueCustomers = customers.Distinct().ToArray();

```

If you need to be aware of potential duplicates, you could use `GroupBy( c => c )` first to identify which items have duplicates.

Finally, if you don't want to use LINQ, you can build the dictionary on the fly and use a precondition check when adding each item:

```
var customerDictionary = new Dictionary<Customer,string>();
foreach( var cust in customers )
{
    if( !customerDictionary.ContainsKey(cust) )
        customerDictionary.Add( cust, cust.SomeKey ); 
}

```
What is your definition of duplicate in this case? 

If its simply the same object instance (the same pointer) then that's simple, you can use any of the methods in the other answers given here. 

Sometimes though the concept of equality is not so straight forward, is a different object instance with the ***same data*** equal? In that case you probably want an implementation of an IEqualityComparer to help you.