You can get a list of the unique values using the constructor of HashSet
List<int> numbers = new() { 1, 2, 2, 2, 5, 6}; List<int> uniqueValues= new HashSet<int>(numbers).ToList(); int numberOfElements = uniqueValues.Count;
Credit to: https://josipmisko.com/posts/c-sharp-unique-list