Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve Distinct Values From NotePad Elements

Tags:

c#

asp.net

I've a notepad file that has the following format:

[email protected]
[email protected]
[email protected]
[email protected]

I require the following distinct output:

[email protected]
[email protected]

Tried the following code but it doesn't get distinct values:

List<string> lst = new List<string>();
foreach (string line in File.ReadLines(values))
{
   line.Distinct().ToString();
   lst.Add(line);    
}

I know, this may seem stupid and guessing, missed something here.

like image 631
AT-2017 Avatar asked Sep 09 '26 02:09

AT-2017


1 Answers

First you should read all the lines and then get the distinct lines:

var allLines = File.ReadLines(values);
var distinctLines = allLines.Distinct();
foreach(var distinctLine in distinctLines)
{
    Console.WriteLine(distinctLine);
}
like image 54
Christos Avatar answered Sep 11 '26 14:09

Christos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!