https://msdn.microsoft.com/en-us/library/mt693040.aspx以下のコードをlinq経由で比較することができます。左から右、右から左のリストを比較する方法がありますか?csharpの比較リスト<t>右から左へ
class CompareLists
{
static void Main()
{
// Create the IEnumerable data sources.
string[] names1 = System.IO.File.ReadAllLines(@"../../../names1.txt");
string[] names2 = System.IO.File.ReadAllLines(@"../../../names2.txt");
// Create the query. Note that method syntax must be used here.
IEnumerable<string> differenceQuery =
names1.Except(names2);
// Execute the query.
Console.WriteLine("The following lines are in names1.txt but not names2.txt");
foreach (string s in differenceQuery)
Console.WriteLine(s);
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
/*出力: 次の行がnames1.txtにあるが Potra、クリスティーナ ノリエガ、はFabricio おやおや、カムフー 豊島、ティム ガイ、Weyの元 ガルシアを、names2.txtありませんDebra */
注:左から右は、ソースリストからデスティネーションリストを意味し、逆も同様です。
あなたが見えるように設定されている結果を何を期待しますか? – itsme86
これはあなたが欲しいものですか? IEnumerable differenceQuery = names1.Except(names2).Reverse(); –
この質問を見てください:http://stackoverflow.com/questions/22173762/check-if-two-lists-are-equal – oldovets