C# (Program.cs):
using System;
using System.Linq;
namespace GoesTo
{
class Program
{
static void Main(string[] args)
{
string[] words = { "Welcome", "to", "CodeBoxy" };
string shortestWord = words.OrderBy(w => w.Length).FirstOrDefault(); //Find shortest word
int shortestWordLength = words.Min(w => w.Length); //Find the length of the shortest word
Console.WriteLine(shortestWord + "\n" + shortestWordLength);
}
}
}
結果:
說明:
簡單使用goes to(=>)搜尋字串長度最小值。
沒有留言:
張貼留言