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

image_pdfimage_print
   
 

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());
    }
}

    


This entry was posted in LINQ. Bookmark the permalink.