You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
foreach (int element in fibNumbers)
{
count++;
Console.WriteLine($"Element #{count}: {element}");
}
The output displays Element #1: 0.
This is incorrect as lists are zero based, so this is element 0.
While this seems basic, it threw me as I'm just learning C#, and while I thought lists were zero based, I had to stop and spend time trying to understand why this appeared to show an IEnumerable that was not zero based.
Recommended change
foreach (int element in fibNumbers)
{
Console.WriteLine($"Element #{count}: {element}");
count++;
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: d710feeb-8f03-b211-a070-155938929d6b
Version Independent ID: c980ea8e-ffb4-fbb1-1761-292858616cdd
Activity
Increment count after writing the information
BillWagner commentedon Jan 4, 2021
Thanks for noting this @ScottStabb
I just opened PR #22214 to fix this issue.
Increment count after writing the information (#22214)