Example of Anonymous Type Indexes in For Loop in C#

Published on June 21, 2015 by abundantcode

Filed under LINQ

Last modified June 21, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 6199 times

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

Leave a Comment


x

You might be Interested in these Posts

VB.NET and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

VB.NET and LINQ – Filter elements from object collection using where clause

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...