如何更改此处的 linq 语句,以便找到包含子字符串为“third”的用户的公司?
目前它只在搜索完整用户名时有效,即 contains("third user") 因为它在列表中搜索匹配项,而不是字符串。
class Company
{
public Company(List<User> users) { this.Users = users; }
public List<User> Users { get; set; }
}
class User
{
public User(string name) { this.Name = name; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Company> companies = new List<Company>();
Company company1 = new Company(new List<User>(){ new User("first user"), new User("second user") });
Company company2 = new Company(new List<User>() { new User("third …Run Code Online (Sandbox Code Playgroud)