Example of Anonymous Type Indexes in For Loop in C#

The anonymous type (var) can be used to initialize the indexes in a for loop or the object within the for each loop. Below is a sample code snippet demonstrating the usage of the anonymous types in the For loop .

Example of Anonymous Type Indexes in For Loop in C#

using System;

namespace AbundantCodeConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = new int[] { 1, 1, 2, 3, 4, 8, 33, 2 };
            for (var indexer = 0; indexer < numbers.Length; indexer++)
                Console.WriteLine(numbers[indexer]);
            Console.ReadLine();
        }
     
    }
}