比较2 CSV文件在C#中的建议吗? [英] Comparing 2 CSV files in C# advice?

查看:133
本文介绍了比较2 CSV文件在C#中的建议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要开发,其中两个的CSV文件进行比较的应用程序。第一文件具有电子邮件地址的列表。第二列表还具有电子邮件地址,但是包括名称和地址信息。所述第一列表包含需要从所述第二列表中删除的电子邮件地址。我从$ C $的CProject网站,其中工程pretty的以及快速的CSV阅读器。应用程序将不能访问的数据库服务器。一个新的文件与西港岛线被认为是经过验证的数据生成。这意味着,它不会从所述第一文件包含任何信息。

I need to develop an application where two csv files are compared. The first file has a list of email addresses. The second list also has email addresses, but includes name and address info. The first list contains email addresses that need to be removed from the second list. I have the Fast CSV reader from the CodeProject site which works pretty well. The application will not have access to a database server. A new file wil be generated with data that is considered verified. Meaning, it will not contain any of the information from the first file.

推荐答案

如果你读这两个列表到集合中,你可以使用LINQ来确定地址的子集。

If you read both lists into collections, you can use Linq to determine the subset of addresses.

下面是我掀起了你一个简单的例子类。

Here is a quick example class I whipped up for you.

using System;
using System.Linq;
using System.Collections.Generic;

public class RemoveExample
{
    public List<Item> RemoveAddresses(List<Item> sourceList, List<string> emailAddressesToRemove)
    {
        List<Item> newList = (from s in sourceList
                              where !emailAddressesToRemove.Contains(s.Email)
                              select s).ToList();
        return newList;
    }

    public class Item
    {
        public string Email { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
    }
}

要使用它,看了你的CSV到一个列表,然后通过它,您的地址列表来删除一个目录到方法。

To use it, read your csv into a List, then pass it, and your list of addresses to remove as a List into the method.

这篇关于比较2 CSV文件在C#中的建议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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