Sorting a List<t> (What was I thinking??)

This entry updated after a night’s sleep and the return of my cerebral cortex.

In one of my earlier entries you’ll find something approximating this bit of nonsense…

public string DoSort(List<string> words)
{
List<string> temp = words.Sort(); // No, but thanks for playing.
return temp
}

Replace with

words.Sort();   // sorts list in place.

 

iStock_BoyWithBrainXSmall

For those of you who commented on my earlier attempt to explain how this would compile I can only tell you that I carefully tested it, but must have been sleep walking. I have a section in both of my books on C# that clearly says I was wrong, I have no idea what brain malfunction caused this, but I find that when this kind of thing happens the best thing is to take a nice long bath and throw the radio in.

 

 

 

-j

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in z Silverlight Archives. Bookmark the permalink.