Can anyone let me know how can access an element of a list that has been added to a list of list. I'll mention the code.
List<string> str = new List<string>();
List<List<string>> stud = new List<List<string>>();
A method has been defined that inserts data into str and after the method gets over.
stud.Add(str);
The method and stud.Add(str) is on a button click...... so, each time str contains different data.......
the problem is I want to search in whole of stud i.e. all the str created, whether str[0]==textBox3.Text;
I'm confused in the For loops...how to reach to all the str[0] in stud to verify the condition.
To convert a list to a string, use Python List Comprehension and the join() function. The list comprehension will traverse the elements one by one, and the join() method will concatenate the list's elements into a new string and return it as output.
List is constructed by placing expressions within square brackets separated by commas. List is [10, 20]. The elements of a list can be accessed in two ways. The first way is via our familiar method of multiple assignment, which unpacks a list into its elements and binds each element to a different name.
An element can be retrieved from the ArrayList in Java by using the java. util. ArrayList. get() method.
In C# you can simply return List<string> , but you may want to return IEnumerable<string> instead as it allows for lazy evaluation.
You can use
if (str.Any(stud.Any(s => s == textBox3.Text)))
{
// Do something...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With