c# - 从嵌套列表中查找字符串

c# - find a string from a nested list

我有以下嵌套结构。

List<SomeType> 有另一个 List<AnotherType> 列表,内部有一个 array of strings users.

public class SomeType
{
    public string EmployeeNo { get; set; }

    public List<AnotherType> AnotherType { get; set; }
}

public class AnotherType
{
    public string UserName { get; set; }

    public string[] Users { get; set; }
}

假设我想在字符串数组 Users 中搜索一个值。我该怎么做。

你想做这样的事情吗?

var query = SomeTypeList
    .Where(sometype => sometype.AnotherType.Any(
        anothertype => anothertype.Users.Any(
             user => user.Contains("user to search for"))))

看起来像重复的: