How to sort Generic List Asc or Desc?

How about: estate.Images. OrderByDescending(est => est. IsProfile).ToList() This will order the Images in descending order by the IsProfile Property and then create a new List from the result.

Instead of -> – Anton Gogolev Feb 10 '09 at 12:00 Fixed that for Ray. – Jon Skeet Feb 10 '09 at 12:01 Thanks for the answer and sorry for my unnecessary, I don't know why I didn't take attention the word under OrderBy on the intellisense. Thanks again – Barbaros Alp Feb 10 '09 at 12:01 Woops, thanks!

:) – Ray Booysen Feb 10 '09 at 12:03 Is there any other way of just ordering the List instead of creating a new list except Marc's answer – Barbaros Alp Feb 10 '09 at 12:07.

You can use . OrderByDescending(...) - but note that with the LINQ methods you are creating a new ordered list, not ordering the existing list. If you have a List and want to re-order the existing list, then you can use Sort() - and you can make it easier by adding a few extension methods: static void Sort(this List source, Func selector) { var comparer = Comparer.

Default; source. Sort((x,y)=>comparer. Compare(selector(x),selector(y))); } static void SortDescending(this List source, Func selector) { var comparer = Comparer.

Default; source. Sort((x,y)=>comparer. Compare(selector(y),selector(x))); } Then you can use list.

Sort(x=>x. SomeProperty) and list. SortDescending(x=>x.

SomeProperty).

– Barbaros Alp Feb 10 '09 at 12:04 Well, in a very small way, but compared to data-binding you'll never notice it. – Marc Gravell? Feb 10 '09 at 12:26 Thank you very much – Barbaros Alp Feb 10 '09 at 13:59 This is really helpful.

Could this be extended to also do ThenOrderBy? – Ash Machine May 18 '09 at 22:56 @Ash, not "as is", since it is doing an immediate sort.It would need a bit more glue to do it - more than I can write at this moment... – Marc Gravell? May 18 '09 at 23:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions