Test if all values in a list are unique

后端 未结 8 1958
温柔的废话
温柔的废话 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 10:13

    The similar logic to Distinct using GroupBy:

    var isUnique = theList.GroupBy(i => i).Count() == theList.Count;
    

提交回复
热议问题