寻找一个C#算法来比较两个列表

寻找一个C#算法来比较两个列表

本文介绍了寻找一个C#算法来比较两个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试,但没有找到一个完全符合我需要的解决方案。所以我转向这里的小组寻求帮助。



我有两个List< string>我要比较的对象,我想找到两个列表中不同的项目。这两个列表已按字母顺序排序。



所以我需要一种方法来遍历列表以找到两个列表中都没有出现的内容。



例如...



列表1 = Apple,Banana,Carrot,葡萄,李子
清单2 =苹果,胡萝卜,葡萄,芒果,李子





我想要的是能够在列表1中找到 Banana ,在列表2中找到 Mango - 以我知道哪个列表的方式来自。



谢谢!

解决方案



I have been experimenting but haven't found a solution that does exactly what I need it to do. So I am turning to the group here to ask for help.

I have two List<string> objects that I want to compare, and I want to find any item that is not the same in both lists. Both lists are already sorted into alphabetical order.

So I need a way to iterate through the lists to find anything that does not appear in both lists.

For example...

List 1 = Apple, Banana, Carrot, Grape, Plum
List 2 = Apple, Carrot, Grape, Mango, Plum



What I want is to be able to find "Banana" in List 1 and "Mango" in List 2 - and in a way that I know which list it came from.

Thanks!

解决方案




这篇关于寻找一个C#算法来比较两个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:02