Example of Anonymous Type Indexes in For Loop in C#


This content was proof-read by Grammarly. You can Try Grammary for FREE

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();
        }
     
    }
}
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: