public class UnitTest1 { public class Person { public string Name { get; set; } public int Age { get; set; } } public class SCompare : IEqualityComparer<Person> { public bool Equals(Person a, Person b) { return a.Name.Equals(b.Name) && a.Age.Equals(b.Age); } public int GetHashCode(Person obj) { return obj.GetHashCode(); } } [Fact] public void Test0() { var s = "one,two,three,four,five,six,seven,eight,nine"; string[] listA = s.Split(","); string[] listB = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; string[] listC = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; var resultA = listA.SequenceEqual(listB); var resultB = listA.SequenceEqual(listC); var listA1 = new List<Person> { new Person() { Name = "zangsan", Age = 256 }, new Person() { Name = "lisi", Age = 128 } }; var listB1 = new List<Person> { new Person() { Name = "zangsan", Age = 256 }, new Person() { Name = "lisi", Age = 128 } }; var listC1 = new List<Person> { new Person() { Name = "wangwu", Age = 256 }, new Person() { Name = "liaoliu", Age = 128 } }; var resultAA = listA1.SequenceEqual(listB1, new SCompare()); var resultBB = listA1.SequenceEqual(listC1, new SCompare()); } }
标签:SequenceEqual,Name,Age,Linq,Person,var,new,public From: https://www.cnblogs.com/hofmann/p/16640121.html