Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class SortArrayByLength
- {
- static void Main()
- {
- // Initialize a List of strings.
- List<string> array = new List<string>{ "11", "1", "1133", "144441", "4311", "76572211" };
- // Send the List to the method.
- foreach (string s in SortByLength(array))
- {
- Console.WriteLine(s);
- }
- }
- static IEnumerable<string> SortByLength(IEnumerable<string> e)
- {
- // Use LINQ to sort the array received and return a copy.
- var sorted = from s in e
- orderby s.Length ascending
- select s;
- return sorted;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment