static void Main() { Console.WriteLine("------------------------------Ex.1------------------------------"); Point3D point = new Point3D(10, 20, 30); Console.Write("Override ToString(): "); Console.WriteLine(point.ToString()); //ex2 Console.WriteLine("------------------------------Ex.2------------------------------"); Console.WriteLine(Point3D.PointO); //ex3 Console.WriteLine("------------------------------Ex.3------------------------------"); Console.Write("Distance : "); Point3D point1 = new Point3D(0,0,0); Point3D point2 = new Point3D(0,3,4); Console.WriteLine(CalculateDistance.Calc(point1,point2)); Console.WriteLine("------------------------------Ex.4------------------------------"); Path path = new Path(); path.AddInPath(point1); path.AddInPath(point2); Console.WriteLine(path.Points[0]); PathStorage.SaveData(path); Path loadedPath = new Path(); loadedPath = PathStorage.LoadData(); Console.WriteLine("The loaded path has points :"); foreach (var item in loadedPath.Points) { Console.WriteLine(item); } }
public static Path LoadData() { StreamReader reader = new StreamReader(dataPath); Path newPath = new Path(); using (reader) { //firsl line of the file string line = reader.ReadLine(); while (line != null) { string[] clearFormat = line.Split(new char[] {'[',']',','});//removing formats // list to hold point coordinats List<short> pointCoord = new List<short>(); for (int i = 0; i < clearFormat.Length; i++) { if (clearFormat[i] != "") { pointCoord.Add(short.Parse(clearFormat[i])); } } //creating the point Point3D pointForAdd = new Point3D(pointCoord[0],pointCoord[1],pointCoord[2]); //adding point in the path newPath.AddInPath(pointForAdd); //taking the next line in the file line = reader.ReadLine(); } return newPath; } }