Access to List <List <string>> Elements

Can someone tell me how to access the list item that has been added to the list list. I mentioned the code.

List<string> str = new List<string>();
List<List<string>> stud = new List<List<string>>();

A method is defined that inserts data into str even after the method completes.

stud.Add(str);

The method and stud.Add (str) is on the button ... therefore, each time str contains different data ........

The problem is what I want to look for in general stud, i.e. all created str, independently str [0] == textBox3.Text;

I got confused in For loops ... how to get to all str [0] in stud to check the condition.

+5
source share
4 answers
var stud =  new List<List<string>>();
foreach( var list in stud )
{
    foreach( item in list )
    {
        if ( item == textBox3.Text )
            //...
    }
}

If you want to search for the first item in the first list, you can do the following:

if ( stud.Count > 0 )
{
    var list = stud[0]
    if ( list.Count > 0 && list[0] == textbox3.Text )
        //...
}
0
source

if (str.Any(stud.Any(s => s == textBox3.Text)))
{
    // Do something...
}
+5
foreach(List<string> innerList in stud)
{
    foreach(string str in innerLst)
    {
        if(!String.IsEmptyOrNull(str) && str.Equals(textBox3.Text))
        {
            ...
        }
    }
}
+3
source

The method SelectManywill smooth your list items:

// untested
var all = stud.SelectMany(...)
              .Where(...)
0
source

All Articles