Test if all values in a list are unique

后端 未结 8 1959
温柔的废话
温柔的废话 2020-12-03 09:22

I have a small list of bytes and I want to test that they\'re all different values. For instance, I have this:

List theList = new List

        
8条回答
  •  再見小時候
    2020-12-03 09:54

    One can also do: Use Hashset

    var uniqueIds = new HashSet(originalList.Select(item => item.Id));
    
                if (uniqueIds.Count != originalList.Count)
                {
                }
    

提交回复
热议问题