Skip to content

Instantly share code, notes, and snippets.

@posaunehm
Created April 2, 2013 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posaunehm/5291411 to your computer and use it in GitHub Desktop.
Save posaunehm/5291411 to your computer and use it in GitHub Desktop.
std_adjacent like behavior in C# (of course, using linq :) )
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