如何比较2 List< string>对象以从List< string>获取缺少的值

如何比较2 List< string>对象以从List< string>获取缺少的值

问题描述:

如何使用"NOT IN"获取丢失的数据,并将其添加到"foo"列表中.

How do I use the "NOT IN" to get the missing data, to be added to "foo" List.

var accessories = new List<string>(); 
var foo = new List<string>();

accessories.Add("Engine");
accessories.Add("Tranny");
accessories.Add("Drivetrain");
accessories.Add("Power Window");

foo.Add("Engine");
foo.Add("Tranny");
foo.Add("Power Window");

foreach(var v in foo.Where(x => x??).???)
{
    foo.Add(v);  //Add the missing "Drivetrain" to it...
}

使用从MSDN:

除产生两个序列的集合差异.

Except Produces the set difference of two sequences.