Home > Blockchain >  c# - find a string from a nested list
c# - find a string from a nested list

Time:03-03

I have the following nested structure.

List<SomeType> which has another list of List<AnotherType> which internally has an 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; }
}

Lets say I want to search for a value in the array of string Users. How can I do that.

CodePudding user response:

Are you trying to do something like this?

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

Looks like a duplicate: stackoverflow: C# LINQ Filter deep nested list

  • Related