using System.Collections.Generic;
public static void Main()
var myList = new List<int> { 1, 1, 9, 2, 2, 3, 9, 4, 5, 5, 1, 9, 9 };
var firstDuplicate = myList.First();
var lastDuplicate = myList.Last();
var myFilteredList = myList
.SkipWhile(l => l == firstDuplicate)
.SkipLastWhile(l => l == lastDuplicate)
Console.WriteLine(string.Join(", ", myFilteredList));
public static class Helper
public static IEnumerable<TSource> SkipLastWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
var buffer = new List<TSource>();
foreach (var item in source)
foreach (var bufferedItem in buffer)
yield return bufferedItem;