这循环怎么做？

sv23vg 2012-10-04 12:17:51
foreach(var c in list)
{
if()
{

...
}
}

...全文
121 8 打赏 收藏 转发到动态 举报

8 条回复

w051108 2012-10-04
• 打赏
• 举报

break掉？

• 打赏
• 举报

sv23vg 2012-10-04
• 打赏
• 举报

[Quote=引用 3 楼 的回复:]

[/Quote]

dalmeeme 2012-10-04
• 打赏
• 举报

``````        List<int> list = new List<int>() { 1, 2, 3, 4, 5 };
for (int i = 0; i < list.Count; i++)
{
if (list[i] >= 3)
{
for (; i < list.Count; i++)
Console.WriteLine(list[i]);
break;
}
}``````
dalmeeme 2012-10-04
• 打赏
• 举报

``````		List<int> list = new List<int>() { 1, 2, 3, 4, 5 };
for (int i = 0; i < list.Count; i++)
{
if (list[i] == 3)
{
for (; i < list.Count; i++)
Console.WriteLine(list[i]);
break;
}
}``````
dianyancao 2012-10-04
• 打赏
• 举报

C#怎么在执行完一句判断语句后，在循环内将其移除？
threenewbee 2012-10-04
• 打赏
• 举报

``````List<int> list = new List<int>() { 1, 3, 10, 6, 4, 2, 15, 1, 10, 8, 9, 20, 4, 11, 3 };
foreach (int i in list)
{
if (i > 10)
{
Console.WriteLine("{0} larger than 10! Loops are breaked.", i);
break;
}
else
{
Console.WriteLine(i);
}
}``````

``````List<int> list = new List<int>() { 1, 3, 10, 6, 4, 2, 15, 1, 10, 8, 9, 20, 4, 11, 3 };
foreach (int i in list.TakeWhile(x => x <= 10))
Console.WriteLine(i);
Console.WriteLine("{0} larger than 10! Loops are breaked.", list.First(x => x > 10));``````
stonespace 2012-10-04
• 打赏
• 举报

110,591

• 近7日
• 近30日
• 至今