Example of Anonymous Type Indexes in For Loop in C#

Published on June 21, 2015 by abundantcode

Filed under LINQ (General)

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 2095 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++)
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


You might be Interested in these Posts

How to Get the Top 5 elements from a List in C# ?

If you want to get the top 5 elements from a list in C# or skip the first item and get the next five...

For Each loop in Java

Java 5 brought in the support in the support for foreach loop that lets the developers to iterate ov...

Do-While Loop example in Java

The do-while loop in java is similar to the while loop except that the do-while loop is guaranteed t...