我正在使用UPS记录读取文件&将它们添加到动态IList数组但不希望有任何重复记录。 所以我用.Contains检查它们但是它总是在"中首先记录"案件 在"第二个日志"如果它总是返回真实。
我正在以完全相同的方式阅读相同的文件,因此在第一次阅读后,只有重复的记录,但程序会不断添加它们。
IList<UpsRecord> new_records = CVSReader.ParseCsvRows(settings.fileAddress);
foreach(UpsRecord record in new_records){
// first log
Console.WriteLine(arrayUpsRecords.Contains<UpsRecord>(record));
if (!arrayUpsRecords.Contains<UpsRecord>(record))
{
arrayUpsRecords.Add(record);
// second log
Console.WriteLine(arrayUpsRecords.Contains<UpsRecord>(record));
}
}
我正在使用FileHelpers读取文件像这样:
class CVSReader
{
public static IList<UpsRecord> ParseCsvRows(string file_path)
{
FileHelperEngine FileHelper = new FileHelperEngine(typeof(UpsRecord));
IList<UpsRecord> recordsArray = new List<UpsRecord>();
recordsArray = FileHelper.ReadFile(file_path) as IList<UpsRecord>;
return recordsArray;
}
}
UpsRecord类型:
[DelimitedRecord(",")]
public class UpsRecord
{
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string service;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string tracking;
//[FieldIgnored()]
public string x2;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string void_indicator;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string weight;
//[FieldIgnored()]
public string x5;
//[FieldIgnored()]
public string x6;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string billto;
//[FieldIgnored()]
public string x8;
//[FieldIgnored()]
public string x9;
//[FieldIgnored()]
public string x10;
//[FieldIgnored()]
public string x11;
//[FieldIgnored()]
public string x12;
//[FieldIgnored()]
public string x13;
//[FieldIgnored()]
public string x14;
//[FieldIgnored()]
public string x15;
//[FieldIgnored()]
public string x16;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string attn;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string name;
//[FieldIgnored()]
public string x19;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string addr1;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string addr2;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string addr3;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string postcode;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string country;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string city;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string state;
//[FieldIgnored()]
public string x27;
//[FieldIgnored()]
public string x28;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string receiver_acc;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string residential;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string timestamp;
[FieldQuoted('"', QuoteMode.OptionalForBoth)]
public string cost;
}