C# Не могу понять, как вытащить массив из файла и перемножить его C#

Не знаю как работает StreamReader и тд, поэтому не могу решить задачу

Даны два файла вещественных чисел с именами NameA и NameB, содержащие элементы прямоугольных матриц A и B (по строкам), причем начальный элемент каждого файла содержит количество столбцов соответствующей матрицы. Создать файл той же структуры с именем NameC, содержащий произведение A·B. Если матрицы A и B нельзя перемножать, то оставить файл NameC пустым

Пока имею такой, неработающий код:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace laba5
{
    class Program
    {
        static void Main(string[] args)

        {
            int NameA = 0, NameB = 0, NameC = 0;
            try
            {
                using (StreamReader sr = new StreamReader("NameA.txt"))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }

                    NameA = Convert.ToInt32(sr);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            try
            {
                using (StreamReader sr1 = new StreamReader("NameB.txt"))
                {
                    string line;
                    while ((line = sr1.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }

                    NameB = Convert.ToInt32(sr1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            StreamWriter ar = new StreamWriter("NameC.txt");
            {
                DirectoryInfo[] cDirs = new DirectoryInfo(@"c:\").GetDirectories();
                using (StreamWriter sw = new StreamWriter("NameC.txt"))
                {
                    foreach (DirectoryInfo dir in cDirs)
                    {
                        NameC = NameA * NameB;
                        sw.WriteLine(NameC);
                    }
                }
            }
            Console.WriteLine(NameC);
        }
    }
}

Ответы (0 шт):