如何使用for循环从c#中的列表中检索值... [英] How to retrieve values from a list in c# using for loop...
本文介绍了如何使用for循环从c#中的列表中检索值...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用for循环从c#中的列表中检索值...
How to retrieve values from a list in c# using for loop...
List<string[]> list = new List<string[]>();
list.Add(new string[] { "Id", "Name", "Age" });
我想使用for循环获取每个值...
I want to get each values using for loop...
推荐答案
所以,你有一个字符串数组列表(有趣,但你应该知道)。
以下是访问值的代码示例:
So, you have a list of string arrays (interesting, but you should know).
Here is a code sample for accessing the values:
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);
请注意,如果这是你的意图,很难用一个for循环来访问这些值 - 我想可以做到,但这不明智,因为你的代码会很乱。
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.
这篇关于如何使用for循环从c#中的列表中检索值...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文