here is my code:
class Program
{
static void Main(string[] args)
{
string sentence = string.Empty;
sentence = Con
Use System.Linq Distinct:
foreach (string s in x.Distinct())
This should do everything you're asking:
class Program
{
static void Main(string[] args)
{
string sentence = string.Empty;
sentence = Console.ReadLine();
var sent = sentence
.Split(' ')
.Distinct()
.OrderBy(x => x);
foreach (string s in sent)
{
Console.WriteLine(s.ToLower());
}
Console.ReadLine();
}
}
Hope it helps!
Use Distinct:
foreach (string s in x.Distinct())
{
Console.WriteLine(s.ToLower());
}
You could use Linq's Distinct extension method:
var sent = sentence.Split(' ').Distinct();
You can also use this to ignore the case of strings when comparing them—e.g. "WORD"
and "word"
would be considered duplicates:
var sent = sentence.Split(' ').Distinct(StringComparer.CurrentCultureIgnoreCase);