Seth Jeffery
24
Q:

c# list foreach

var fibNumbers = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13 };
int count = 0;
foreach (int element in fibNumbers)
{
    count++;
    Console.WriteLine($"Element #{count}: {element}");
}
Console.WriteLine($"Number of elements: {count}");
19
var fibNumbers = new List<int> { 0, 1, 1, 2, 3, 5, 8, 13 };
int count = 0;
foreach (int element in fibNumbers)
{
    count++;
    Console.WriteLine($"Element #{count}: {element}");
}
Console.WriteLine($"Number of elements: {count}");
2
var numbers = new NumberList<int> { 0, 1, 2, 3, 4, 5 };
foreach (int num in numbers)
{
    DoSomething();
}
3
foreach (int num in numbers)
{
  
}
3
someList.ForEach(x => { if(x.RemoveMe) someList.Remove(x); }); 
0
List<string> someList = <some way to init>
someList.ForEach(delegate(string s) {
    <process the string>
});
0

New to Communities?

Join the community