Untitled
unknown
plain_text
3 years ago
1.1 kB
11
Indexable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\example.txt"; // замените на путь к вашему файлу
List<string> lines = ReadLinesFromFile(filePath);
List<string> uniqueLines = GetUniqueLines(lines);
Console.WriteLine("Уникальные строки:");
foreach (string line in uniqueLines)
{
Console.WriteLine(line);
}
}
static List<string> ReadLinesFromFile(string filePath)
{
List<string> lines = new List<string>();
using (StreamReader reader = new StreamReader(filePath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
lines.Add(line);
}
}
return lines;
}
static List<string> GetUniqueLines(List<string> lines)
{
return lines
.Where(line => line.Distinct().Count() == line.Length)
.ToList();
}
}Editor is loading...