Get strings whose length matches that of the shortest string in CSharp
Description
The following code shows how to get strings whose length matches that of the shortest string.
Example
//from w ww . j a va2s .co m
using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
public static void Main() {
string[] names = { "HTML", "CSS", "Java", "Javascript" };
IEnumerable<string> outerQuery = names
.Where(n => n.Length == names.OrderBy(n2 => n2.Length)
.Select(n2 => n2.Length).First());
Console.WriteLine(outerQuery);
}
}
The code above generates the following result.