DEV Community

Discussion on: Find longest word in a given string

Collapse
 
jjtowle profile image
Jason Towle • Edited

Can I chime in with a quick C# and LINQ one liner?

private Longest(string sentance) 
{
     return sentance.Split(' ').OrderByDescending(l => l.Length).FirstOrDefault();
}

Well, the return statement is a one liner :)