Ejemplo n.º 1
0
 public void ReadFromFile(string filename)
 {
     try
     {
         using (StreamReader sr = new StreamReader(filename))
         {
             int n = int.Parse(sr.ReadLine());
             int m = int.Parse(sr.ReadLine());
             array = new int[n, m];
             for (int i = 0; i < n; i++)
             {
                 for (int j = 0; j < m; j++)
                 {
                     array[i, j] = int.Parse(sr.ReadLine());
                 }
             }
         }
     }
     catch (FileNotFoundException ex)
     {
         ConsoleView.PrintWithPause(ex.Message);
     }
     catch (Exception ex)
     {
         ConsoleView.PrintWithPause(ex.Message);
     }
 }
Ejemplo n.º 2
0
 public void WriteToFile(string filename)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(filename))
         {
             sw.WriteLine(array.GetLength(0));
             sw.WriteLine(array.GetLength(1));
             for (int i = 0; i < array.GetLength(0); i++)
             {
                 for (int j = 0; j < array.GetLength(1); j++)
                 {
                     sw.WriteLine(array[i, j]);
                 }
             }
         }
     }
     catch (FileNotFoundException ex)
     {
         ConsoleView.PrintWithPause(ex.Message);
     }
     catch (Exception ex)
     {
         ConsoleView.PrintWithPause(ex.Message);
     }
 }