如果测试列表中的所有值都是唯一的 [英] Test if all values in a list are unique

查看:91
本文介绍了如果测试列表中的所有值都是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有个字节的小名单,我想测试他们都是不同的值。
举例来说,我有这样的:

 列表<位>的thelist =新的List<位> {1,4,3,6,1}; 



什么是检查是否所有的值是不同或不?

$ B $的最佳方式b
解决方案

  isUnique设置布尔= theList.Distinct()计数()== theList.Count()。 


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

List<byte> theList = new List<byte> { 1,4,3,6,1 };

What's the best way to check if all values are distinct or not?

解决方案

bool isUnique = theList.Distinct().Count() == theList.Count();

这篇关于如果测试列表中的所有值都是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆