Created
July 25, 2019 11:00
-
-
Save cbuctok/227bc3721d6763a969eb76f4ef31ffa3 to your computer and use it in GitHub Desktop.
Group By Index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var s = new List<int> { 1,2,3,34,5,678,8,5,4,5,7,8,7,4,3,3,6,8,4}; | |
var groups = s.Select((value,index)=>new { Value= value,Index=index}).GroupBy(i=>i.Index/2,v=>v.Value); | |
var x = groups.ToList(); | |
foreach (var t in x){ | |
var xx = t.ToList(); | |
Console.WriteLine(xx.Count != 2 ? "ONE element " + xx.First() : "TWO elements " + xx.First() + " " + xx.Last()); | |
} | |
Console.WriteLine("Hello World"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment