Q:

comparing two custom objects to prevent duplicates

Hi I have this Bookings object
Booking abc = new Booking { date = DateTime.Today, timeslot= timeslot[1], venue = venue};
waiter xyz = new waiter { id = 1, name = "xyz" };
xyz.bookedList = new List<Booking>();
xyz.bookedList.Add(bookingxyz);

I am looping through the above code. I want to avoid duplicate bookings based on date and timeslot
how can i do this?

A:

Is it duplicates in your list you are trying to avoid ? If yes then you shouldn't use a list as it allow duplicates. 
A more sutable candidate would be Hashset, you will have to add an override to GetHashCode() in Booking and compute an hash based on date and timeslot as explained here
Then just before adding your Booking to the HashSet just verify that the object doesn't already exists using the Contains method 

