Answers for "how do i foreach c#"

C#
31

foreach syntax c#

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}");
Posted by: Guest on January-18-2020
5

how do i foreach c#

//No counter just the foreach.
 //the HelloWorld is the Class objects name nor a public string can be used aswell.
foreach (string element in fibNumbers)
{
    Console.WriteLine(element.HelloWorld);
}
Posted by: Guest on June-29-2020

C# Answers by Framework

Browse Popular Code Answers by Language