Created
April 2, 2013 10:52
-
-
Save posaunehm/5291411 to your computer and use it in GitHub Desktop.
std_adjacent like behavior in C# (of course, using linq :) )
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; | |
namespace EnumurateAdjacent | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var input = new[] {1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 9, 9, 10}; | |
foreach (var i in | |
input.Zip(input.Skip(1), Tuple.Create) | |
.Where(tuple => tuple.Item1 == tuple.Item2)) | |
{ | |
Console.WriteLine("[{0},{1}]", i.Item1, i.Item2); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment