Подсчитать количество символов в каждой строке - C#
Формулировка задачи:
Даны текстовый файл с латиницей и цифрами. Подсчитать количество символов в каждой строке и массив чисел с количествами записать до другого текстового файла.
помогите составить полную программу, я понял как написать открытие а остальные действия не могу понять,помогите
}
using System;
using System.IO; namespace c_file1
{
class Program
{
public static void Main(string[] args)
{
StreamReader sr = new StreamReader( "z:\\test.txt" );
while (sr.Peek()>-1) Console.WriteLine(sr.ReadLine());
sr.Close();
Console.ReadKey(true);
}
}Решение задачи: «Подсчитать количество символов в каждой строке»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.IO;
class WorkWithFile
{
private static List<int> numbers = new List<int>();
static void read(string fileName)
{
FileStream file = null;
StreamReader reader = StreamReader.Null;
try
{
file = new FileStream(fileName, FileMode.Open);
reader = new StreamReader(file);
string s = null;
while (!reader.EndOfStream)
{
numbers.Add(reader.ReadLine().Length);
}
}
catch (IOException exception)
{
Console.WriteLine(exception);
}
finally
{
if (reader != StreamReader.Null)
{
reader.Close();
}
}
}
static void write(string fileName)
{
FileStream file = null;
StreamWriter writer = StreamWriter.Null;
try
{
file = new FileStream(fileName, FileMode.Open);
writer = new StreamWriter(file);
int i = 1;
foreach (var number in numbers)
{
writer.Write("В " + i + " строчке " + number + " символов");
writer.WriteLine();
i++;
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
finally
{
if (writer != StreamWriter.Null)
{
writer.Close();
}
}
}
public static void Main(string[] args)
{
read("input.txt");
write("output.txt");
}
}