Using IComparer for grouping and sorting
<p>I am trying to use IComprarer to a complex sort.
I have this complex type (for sake of simplicity, three ints):</p>

<pre><code>ID | A | B
1  | 1 | 10
2  | 3 | 20
3  | 1 | 30
4  | 3 |  5
5  | 2 | 15
</code></pre>

<p>And i need to Sort by B, but i need to keep A together.
B can be ASC or DESC but I can not separate 'A'</p>

<p>It must order this way:</p>

<pre><code>ID | A | B
3  | 1 | 30
1  | 1 | 10
2  | 3 | 20
4  | 3 |  5
5  | 2 | 15
</code></pre>

<p>There are NOTHING special in A order, the important things are:
B is ordered and the same A must not be separated.</p>

<p>I tried:</p>

<pre><code>public int Compare(Comanda x, Comanda y)
{
    if (x.A == y.A) return 0;
    return x.B.CompareTo(y.B);
}
</code></pre>

<p>But does not work and I even don't know HOW to ask it to google, "group" keyword do not help much.</p>

<p>And also tried to sort twice which, obviously doesn't work (discarded the B order).</p>

<pre><code>list.Sort(new SortByB());
list.Sort(new SortByA());
</code></pre>

<p>How can I do it ?
Thanks</p>

<p>This is not a duplicate of "C# List&lt;> Sort by x then y" bucause i don't want do double-sort. I wanted to GROUP</p>