c# for vs foreach
// A normal For loop looks like this:
// For loop
int length = 100;
for (int index = 1; index < length; index++)
{
// Your code will be here
}
// Exapmle between for loop and foreach loop:
// For loop
List<JCEmployee> JCEmployees = GetJCEmployeesList();
for (int index = 0; index < JCEmployees.Count; index++)
{
Console.WriteLine(JCEmployees[index].Age);
}
// Foreach loop
List<JCEmployee> JCEmployees = GetJCEmployeesList();
foreach(JCEmployee Employee in JCEmployees)
{
Console.WriteLine(item.Age);
}