Use Min to get the shortest word in a string array by comparing string length in CSharp
Description
The following code shows how to use Min to get the shortest word in a string array by comparing string length.
Example
/*from w w w . j a v a2s.com*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public static void Main() {
string[] words = { "cherry", "apple", "blueberry" };
int shortestWord = words.Min(w => w.Length);
Console.WriteLine("The shortest word is {0} characters long.", shortestWord);
}
}
The code above generates the following result.