How to remove duplicate records from a List<T> in C# and return the unique records

kaushik.debnath

New member
Joined
Jul 21, 2021
Messages
1
Programming Experience
10+
I want to remove the duplicates from the List, for that I am using following code:
C#:
public List<ContainerLevelDetailsResponse> ContainerLevelDetails { get; set; }

public class ContainerLevelDetailsResponse
    {  
        public long ContainerId { get; set; }
        public string Container { get; set; }
        public string Pallet { get; set; }
        public string SKU { get; set; }
        public long CaseCount { get; set; }
    }

List<ContainerLevelDetailsResponse> containerLevelDetails =
new List<ContainerLevelDetailsResponse>();

booking.ContainerLevelDetails = containerLevelDetails.Distinct().ToList<ContainerLevelDetailsResponse>();
But its not working and did not giving unique records. Its not able to remove the duplicates.

Please suggest in this.
 
Last edited by a moderator:
Your call to Distinct() is not passing in a lambda which will let it discriminate whether two responses are the same or not.
 
Back
Top Bottom