namespace ConsoleAppTest { public struct AFS { public int x; public int y; public string Name; } internal class Program { static void Main(string[] args) { List l = new List() { new Com(){id=1,Name="boolive"}, new Com(){id=2,Name="boolive"} }; List l1 = new List() { new Com(){id=1,Name="boolive"}, new Com(){id=3,Name="boolive"} }; var DDD= l1.Except(l).ToList(); var DDD1= l.Except(l1).ToList(); List lll = new List() { new Product{id=1,ComId=1}, new Product{id=2,ComId=2}, new Product{id=3,ComId=3}, }; var str = l.Where(s => s.Name.StartsWith("JavaScript")).DefaultIfEmpty().First(); Console.WriteLine("str=" + str.Name); //输出空白 //使用string str1 = ListInt.Where(s => s.StartsWith("JavaScript")).First(); 如去掉DefaultEmpty就会报异常 Console.WriteLine("Hello, World!"); } } public struct Com { public int id { get; set; } public string Name { get; set; } } public class Product { public int id { get; set; } public int ComId { get; set; } public string Name { get; set; } } }