コード例 #1
0
ファイル: Storage.cs プロジェクト: ya-ivanov/SoftUni
 public static void SavePath(string fileName, Path3D path) // Write the Path3D object to a text file
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.GetEncoding("UTF-8")))
         {
             sw.WriteLine(path.ToString());
         }
     }
     catch (Exception)
     {
         throw new Exception("Error white writing to file.");
     }
 }
コード例 #2
0
ファイル: Paths.cs プロジェクト: ya-ivanov/SoftUni
        static void Main()
        {
            Path3D path = new Path3D(new List <Point3D> {
                new Point3D(45, 7, 3),
                new Point3D(-1, -3, 7),
                new Point3D(6, 1, 0),
                new Point3D(-5, -2, 6)
            });                                                                // Create a Path3D object

            //Console.WriteLine(path.ToString());                              // Print it to the console


            Storage.SavePath("myPath.txt", path);                              // Save it in a file
            Path3D newPath = Storage.ToPath3D(Storage.ReadPath("myPath.txt")); // Set newPath object with the Path3D objects created from the

            // contents of the text file
            Console.WriteLine(newPath.ToString());                             // Print the newPath to the console
        }