I have a collection of objects, let's imagine they're strings:
string[] strings = new[]{"ABC", "AAA", "ADA", "DDB", "OEO"};
I need to perform processing on these, thus:
foreach(string s in strings)
{
//do some stuff here
}
but I must always be sure that the processing of these, in this example, uses the "ABC" string first.
Note that although there might be a hundred strings in the list, they will always be unique, so there will never be two "ABC" entries.
I've tried various permutations of using the OrderBy() extension, thus far unsuccesfully.
Any help greatly appreciated.
Edit after Daniel's comment:
I'm really an idiot. What I did worked fine, except I did OrderBy when I needed OrderBy Descending().
foreach(string s in strings.OrderByDescending(s => s.Contains("ABC")))
{
//do things
}
And this does exactly wha开发者_如何学Got I want.
Sorry for the waste of a thread. Would be happy to hear improvements though if any can be made.
Try:
strings.OrderBy(o=>o=="ABC").ThenBy(o=>o);
This will order by the special string, then sort alphabetically.
精彩评论