static void Main(string[] args) //args reprezinta un array de string (eventuali parametrii din command line) { Car c = new Car() { Id = 5, Model = "Focus", Manufacturer = "Ford", Year = 2015, Pictures = new List <Picture>() { new Picture() { Name = "Picture1", FilePath = "C:\\Pictures\\5\\Picture1.jpg" }, new Picture() { Name = "Picture2", FilePath = "C:\\Pictures\\5\\Picture2.jpg" } } }; var carJsonData = File.ReadAllText("5.json"); var objCar = JsonConvert.DeserializeObject <Car>(carJsonData); objCar.AddPicture(new Picture() { Name = "Picture3", FilePath = "C:\\Pictures\\5\\Picture3.jpg" }); var json = JsonConvert.SerializeObject(objCar); File.WriteAllText(string.Format("{0}.json", c.Id), json); /* * string carAsJson = JsonConvert.SerializeObject(c); * * File.WriteAllText(string.Format("{0}.json", c.Id), carAsJson); */ AutoPark ap = new AutoPark(); ap.Add(c); Console.WriteLine(ap); Console.ReadKey(); }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxID.Text)) { MessageBox.Show("ID cannot be empty!"); return; } if (string.IsNullOrEmpty(textBoxModel.Text)) { MessageBox.Show("Model cannot be empty!"); return; } if (string.IsNullOrEmpty(textBoxManufacturer.Text)) { MessageBox.Show("Manufacturer cannot be empty!"); return; } int id = 0; //conversie string ==> int if (!int.TryParse(textBoxID.Text, out id)) { MessageBox.Show(string.Format("{0} is not a number!", textBoxID.Text)); return; } int year = 0; //conversie string ==> int if (!int.TryParse(textBoxYear.Text, out year)) { MessageBox.Show(string.Format("{0} is not a number!", textBoxYear.Text)); return; } ap.Add(new Car() { Id = id, Model = textBoxModel.Text, Manufacturer = textBoxManufacturer.Text, Year = year }); richTextBox1.Clear(); richTextBox1.Text = ap.ToString(); }
//functie care se executa la click private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox_Id.Text)) { MessageBox.Show("Id cannot be empty!"); return; } if (string.IsNullOrEmpty(textBox_Name.Text)) { MessageBox.Show("Name cannot be empty!"); return; } if (string.IsNullOrEmpty(textBox_Faculty.Text)) { MessageBox.Show("Faculty cannot be empty!"); return; } int id = 0; //conversie string ==> int if (!int.TryParse(textBox_Id.Text, out id)) { MessageBox.Show(string.Format("{0} is not a number!", textBox_Id.Text)); return; } sl.Add(new Student() { Id = id, Name = textBox_Name.Text, Faculty = textBox_Faculty.Text }); richTextBox1.Clear(); richTextBox1.Text = sl.ToString(); }