Write a console application that inputs a sentence from the user (assume no punctuation), then determines and displays the non-duplicate words in alphabetical order. Treat uppercase and lowercase letters the same. [Hint: You can use string method Split with no arguments, as in sentence.Split(), to break a sentence into an array of strings containing the individual words. By default, Split uses spaces as delimiters. Use string method ToLower in the select and orderby clauses of your LINQ query to obtain the lowercase version of each word.]
Explanation / Answer
public static IEnumerable GetAlphabetizedUniqueWords(string sentence) { return (sentence ?? string.Empty) .Split() .Select(x => x.ToLowerInvariant()) .Distinct() .OrderBy(x => x); } static void Main( ) { Console.Write("Enter your sentence. No punctuation. : "); foreach (var word in GetAlphabetizedUniqueWords(Console.ReadLine())) Console.WriteLine(word); }