Write a console application that inputs a sentence from the user (assume no punc
ID: 3539043 • Letter: W
Question
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); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.