using System.Collections.Generic;
static class ExtensionMethods
static public int AsInteger(this string source)
if (int.TryParse(source, out result)) return result;
public string Name { get; set; }
public string Amount { get; set; }
static IEnumerable<IEnumerable<Item>> GroupUp(IEnumerable<Item> input)
var sorted = input.OrderBy( item => int.Parse(item.Amount) ).GetEnumerator();
int lastValue = int.MinValue;
var list = new List<Item>();
while (sorted.MoveNext())
var current = sorted.Current;
var currentAmount = int.Parse(current.Amount);
var gap = currentAmount - lastValue;
if (list.Count != 0) yield return list;
lastValue = currentAmount;
if (list.Count != 0) yield return list;
public static void Main()
var list = new List<Item>
new Item { Name = "Jeff", Amount = "20" },
new Item { Name = "Jack", Amount = "10" },
new Item { Name = "Ben", Amount = "16" },
new Item { Name = "Kyle", Amount = "12" }
var groups = GroupUp(list).ToList();
foreach (var g in groups)
Console.WriteLine("{0} {1}", item.Name, item.Amount);