class Program { static void Main() { List<string> searchTerms = new List<string> { "term1", "term2", "term3" }; List<Company> companies = GetCompanies(); // 获取公司列表 List<Company> matchedCompanies = companies.Where(c => searchTerms.Any(s => c.Name.Contains(s))).ToList(); foreach (Company company in matchedCompanies) { Console.WriteLine($"Name: {company.Name}, Location: {company.Location}"); } } static List<Company> GetCompanies() { // 模拟获取公司列表的方法 List<Company> companies = new List<Company> { new Company { Name = "Company A", Location = "Location A" }, new Company { Name = "Company B", Location = "Location B" }, new Company { Name = "Company C", Location = "Location C" }, new Company { Name = "Company D", Location = "Location D" }, }; return companies; } } class Company { public string Name { get; set; } public string Location { get; set; } }
标签:两个,Name,数据检索,companies,Company,List,Location,new From: https://www.cnblogs.com/hkzw/p/18066252