如何比较两个List< String>对彼此? [英] How to compare two List<String> to each other?
本文介绍了如何比较两个List< String>对彼此?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设有
List<string> a1 = new List<string>();
List<string> a2 = new List<string>();
是否可以这样做?
if (a1 == a2)
{
}
推荐答案
如果要检查列表中的元素是否相等且顺序相同,可以使用 SequenceEqual
:
If you want to check that the elements inside the list are equal and in the same order, you can use SequenceEqual
:
if (a1.SequenceEqual(a2))
查看其在线运行情况: ideone
See it working online: ideone
这篇关于如何比较两个List< String>对彼此?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文