usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;namespacesample3{classProgram {Static voidMain (string[] args) { varStudent1 =NewList<student>(); Student1. ADD (NewStudent () {name ="Zhang San", subject ="English", score = the }); Student1. ADD (NewStudent () {name ="John Doe", subject ="English", score = the }); Student1. ADD (NewStudent () {name ="Harry", subject ="English", score = the }); Student1. ADD (NewStudent () {name ="Qian", subject ="English", score = About }); varStudent2 =NewList<student>(); Student2. ADD (NewStudent () {name ="John Doe", subject ="English", score = the }); Student2. ADD (NewStudent () {name ="Harry", subject ="Mathematics", score = the }); Student2. ADD (NewStudent () {name ="Zhao Liu", subject ="Mathematics", score = - }); //var exp1 = student1. Where (a = Student2. Any (t = a.name.contains (t.name))). ToList (); //using exists can also be literally better understood and more efficient varEXP1 = Student1. Where (a = Student2. Exists (t =a.name.contains (T.name)). ToList (); Console.WriteLine ("-- Find the data that Student1 and student2 always exist--"); foreach(varIteminchEXP1) {Console.WriteLine ("{0} \ t {1} \ t \ {2}", Item.name, Item.Subject, Item.score); } //var exp2 = student1. Where (a = Student2. All (t =!a.name.contains (t.name))). ToList (); //using exists can also be literally better understood and more efficient varEXP2 = Student1. Where (a =!student2. Exists (t =a.name.contains (T.name)). ToList (); Console.WriteLine ("-- find data that exists in the Student1 collection and Student2 does not exist--"); foreach(varIteminchEXP2) {Console.WriteLine ("{0} \ t {1} \ t \ {2}", Item.name, Item.Subject, Item.score); } console.read (); /*-- Find the data that Student1 and student2 always exist--John Doe English 95 Harry English 69 --find data that exists in the Student1 collection and Student2 does not exist--Zhang San English 89 qian English */ } } Public classStudent {/// <summary> ///name/// </summary> Public stringname; /// <summary> ///Subjects/// </summary> Public stringsubject; /// <summary> ///score/// </summary> Public intscore; } }
C # Compares two list sets, two sets exist at the same time or a set exists in the B set without