> I have a class that represents a Menu Tab:
>
[quoted text clipped - 4 lines]
> public int SortOrder;
> }
Really with public fields? Can't say I like the look of that much...
anyway, moving on to your actual question :)
> I then load them in a Generic like:
>
[quoted text clipped - 10 lines]
> How can I make the Collection sort using the SortOrder property of the
> MenuTab class?
Is it fair to assume that the SortOrder numbers will be *reasonably*
small (so that taking one from another will always give a sane result)?
If so:
C# 2:
menus.Sort(delegate(MenuTab mt1, MenuTab mt2)
{ return mt1.SortOrder-mt2.SortOrder; }
);
C# 3:
menus.Sort( (mt1, mt2) => mt1.SortOrder-mt2.SortOrder );
(Otherwise you should call mt1.SortOrder.CompareTo(mt2.SortOrder)) but
that's a bit longer than it really needs to be.)
Alternatively, in C# 3:
menus = menus.OrderBy(tab => tab.SortOrder).ToList();
Note that that creates a *new* list though - so if you've got anything
else with a reference to the old list, it won't be updated.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk