retrieves all strings in an array whose length matches that of the shortest string : First « LINQ « C# / C Sharp






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

 








Related examples in the same category

1.Use First, Last with expression
2.First with string method
3.Use First to return the first matching element as a Product
4.First operator