Example of Anonymous Type Indexes in For Loop in C#


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try 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();
        }
     
    }
}

Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: