using System.Collections.Generic;
public static void Main()
List<BW> lst = new List<BW>(){
new BW(){ shape = "MN11", quantity = 20},
new BW(){ shape = "MN11", quantity = 10},
new BW(){ shape = "MN22", quantity = 14},
new BW(){ shape = "MN22", quantity = 20},
new BW(){ shape = "ANT", quantity = 16},
new BW(){ shape = "ANT", quantity = 18},
new BW(){ shape = "ANT", quantity = 20},
new BW(){ shape = "ANT", quantity = 10}
string preShape = "MN22";
var tempList = lst.GroupBy(c=>c.shape).Select(g=> new {shapeGroup = g.Key, BW = g.OrderBy(c=> c.shape.Equals(preShape)).ThenByDescending(c=>c.quantity)}).OrderByDescending(g=>g.shapeGroup.Equals(preShape));
foreach (var shape in tempList)
var lastGroupBW_Item = shape.BW.LastOrDefault();
foreach (var bw in shape.BW)
if(shape.BW.ToList().IndexOf(bw) > 0 )
shape.BW.OrderBy(c=>c.quantity == lastGroupBW_Item.quantity).ThenBy(c=>c.quantity);
Console.WriteLine("{0}|{1}", bw.shape,bw.quantity);
public static void Swap<T>(IList<T> list, int indexA, int indexB)
list[indexA] = list[indexB];
public string shape{get;set;}
public int quantity{get;set;}