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
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
The method SelectManywill smooth your list items:
// untested
var all = stud.SelectMany(...)
.Where(...)
0