.NET 4.x Работа с текстом (почему выводит последнюю строку ? ) - C#
Формулировка задачи:
почему выводит последнюю строку ?
я питаюсь вывести самою длинною строку .
Листинг программы
- class MainClass
- {
- static string result;
- static int Length_ = 0;
- public static string String(string pach)
- {
- UTF8Encoding utf8 = new UTF8Encoding();
- int count = System.IO.File.ReadAllLines(pach).Length;
- StreamReader readr = new StreamReader(pach, utf8);
- for (int i = 0; i < count; i++)
- {
- string str = readr.ReadLine();
- if (str.Length > Length_)
- {
- result = str;
- }
- Length_ = str.Length;
- }
- readr.Close();
- return result;
- }
- public static void Main(string[] args)
- {
- Console.Write("Введите имья файла :");
- string pach = Console.ReadLine();
- Console.WriteLine(String(pach));
- Console.ReadKey();
- }
Решение задачи: «.NET 4.x Работа с текстом (почему выводит последнюю строку ? )»
textual
Листинг программы
- static void Main(string[] args)
- {
- string longest = "", temp;
- using (StreamReader file = new StreamReader("temp.txt", new UTF8Encoding()))
- {
- while (!file.EndOfStream)
- {
- temp = file.ReadLine();
- if (longest.Length < temp.Length)
- longest = temp;
- }
- }
- Console.WriteLine(longest);
- Console.ReadKey();
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д