是否可以知道或检查 List1 中的所有元素是否都是 List2 的一部分? 例如,如果我有
List1 = { 1,2,3,4 }
List2 = { 1,2,3,5,6,4 }
如果 List 1 中的所有元素都在 List 2 中,我想得到 True,否则为 False
Note : Without ForLoop
列表可以是整数列表,字符串,...等
最佳答案
using System.Linq;
bool allInList2 = !List1.Except(List2).Any();
关于c# - 检查 List1<T> 中的所有元素是否都在 List2<T> C# 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8802997/