예제 #1
0
        public void SaveCar(Car car)
        {
            string fullName = Path.Combine(_filePath, "OurCar.json");

            string carContents = JsonConvert.SerializeObject(car);

            File.WriteAllText(fullName, carContents);
        }
예제 #2
0
 void SaveCarFromForm()
 {
     var car = new Car();
     car.Color = colorTextBox.Text;
     car.Make = makeTextBox.Text;
     car.Model = modelTextBox.Text;
     int year;
     if (int.TryParse(yearTextBox.Text, out year))
         car.Year = year;
     var service = new CarService();
     service.SaveCar(car);
 }