Friday, April 22, 2016

C# Cool Code : Foreach with Index iterator values

namespace PlayWithCollection
{
    class Program
    {
        static void Main(string[] args)
        {
            List Model = new List() { "1", "2", "3" };
            foreach (var item in Model.Select((value, i) => new { i, value }))
            {

                Console.WriteLine("Collection Object Values : " + item.value);
                Console.WriteLine("Collection Index : " + item.i);
            }
        }
    }

No comments :