Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Chapter 9 Program Write a console or windows app that inputs a sentence from the

ID: 3545173 • Letter: C

Question

Chapter 9 Program

Write a console or windows app that inputs a sentence from the user (assume no punctuation), then

determines and displays the nonduplicate words in alphabetical order. Treat uppercase and lowercase

letters the same. Use a LINQ query to do this.

[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

//Here is the program you asked for


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace LINQtoArrays

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Please enter the text");

String input = Console.ReadLine();

String[] words = null;

words = input.Split();

IEnumerable<String> wordsList = words;

var sortedWords = (from word in words

orderby word.ToUpper()

select word.ToUpper()).Distinct();

foreach(var word in sortedWords)

Console.WriteLine(word.ToLower());

Console.ReadKey();

}

}

}