i****a 发帖数: 36252 | 1 【 以下文字转载自 DotNet 讨论区 】
发信人: iMaJia (iMac,iPod,iPad,i馬甲), 信区: DotNet
标 题: How to compare data in an Array and in Xml
发信站: BBS 未名空间站 (Wed Feb 8 17:25:48 2012, 美东)
I am coding in C# .NET 3.5
Let's say I have a List, and an XML file with list if items.
What I want to do is compare the values of the two lists, and get the
difference.
I want two results, 1. items in List but not in XML, 2. items in XML but
not in List.
I can only think of looping through the List against XML, and another loop
for XML against the List.
Is there another way to do this quicker?
Also, I've been using Xml.Ling to process the XML on other parts of the
program and wonder if Ling offers anything I can use for this. | l********a 发帖数: 1154 | 2 it depends what kind of results you are looking for.
if you focus on the content rather than order, then try LINQ
list1.Except(list2) | a9 发帖数: 21638 | 3 还可以反射看一下except是怎么实现的,哈哈。
【在 l********a 的大作中提到】 : it depends what kind of results you are looking for. : if you focus on the content rather than order, then try LINQ : list1.Except(list2)
| i****a 发帖数: 36252 | 4 thank.
so I should port the Xml into a List also?
I guess I'll look at this method and see what it requires
【在 l********a 的大作中提到】 : it depends what kind of results you are looking for. : if you focus on the content rather than order, then try LINQ : list1.Except(list2)
|
|