Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to retrieve values from a list in c# using for loop...
XML
List<string[]> list = new List<string[]>();
                  list.Add(new string[] { "Id", "Name", "Age" });


I want to get each values using for loop...
Posted

1 solution

So, you have a list of string arrays (interesting, but you should know).
Here is a code sample for accessing the values:
C#
List<string[]> list = new List<string[]>();
list.Add(new string[] { "Id", "Name", "Age" });

for(int i=0; i<list.Count; i++)
    for(int j=0; j<list[i].Count(); j++)
        Console.WriteLine(list[i][j]);

// simpler with foreach
foreach(var l in list)
    foreach(string s in l)
        Console.WriteLine(s);

Please note, that will be hard to access the values with just a single for loop if that's your intention - I suppose can be done, but it is not wise, since your code will be a mess.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900