Mega Code Archive

 
Categories / C# / LINQ
 

Retrieves all strings in an array whose length matches that of the shortest string

using System; using System.Collections.Generic; using System.Linq; public class MainClass {     public static void Main() {         string[] names = { "J", "P", "G", "P" };         IEnumerable<string> outerQuery = names           .Where(n => n.Length == names.OrderBy(n2 => n2.Length)                                         .Select(n2 => n2.Length).First());     } }