I have a list that contains strings. How can I sort items in this list by length?

For example, before sorting:

list[0] = "my friend"; list[1] = "Hello"; 

After sorting:

 list[0] = "Hello"; list[1] = "my friend"; 
  • one
    The Sort wrapper function of the List supports a sorting function in which the desired sort condition is written. Open msdn - look. - nick_n_a
  • four
    using linq like so: result = list.OrderBy(x=>x.Length) - Bald
  • @Bald Please post your comment as a response. - Nicolas Chabanovsky

0