Return Tuple from method - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

Return Tuple from method

Demo Code

using System;/* ww  w. ja  v  a 2s. co  m*/
using System.Collections.Generic;
using System.Linq;
static class Indexing
{
   static void Main()
   {
      string[] array = { "first", "second", "third" };
      foreach (var pair in array.WithIndex())
      {
         Console.WriteLine(pair);
      }
   }
   static IEnumerable<(T value, int index)> WithIndex<T> (this IEnumerable<T> source) => source.Select((value, index) => (value, index));
}

Result


Related Tutorials