static void Main(string[] args) { try { Mercedes a = new Mercedes("Mercedes", "CLA", 40000); a.Print(); a.newPrice(15555); Mercedes b = new Mercedes("Mercedes", "Vito", 54587); Audi c = new Audi("Audi", "A4", "Shooting Brake"); Audi d = new Audi("Audi", "R8", "Roadster"); Car[] CarArray = { a, b, new Mercedes("Mercedes", "A180", 16734), c, d, new Audi("TestAudi", "TestModel", "TestCarBodyDesign") }; //Task 3.4.1 foreach (Car Car in CarArray) //Task 3.4.2 { Car.Print(); } var jsonsettings = new JsonSerializerSettings() { Formatting = Formatting.Indented, TypeNameHandling = TypeNameHandling.Auto }; //Task 4.3 var json = JsonConvert.SerializeObject(CarArray, jsonsettings); Console.WriteLine(json); var itemsfromjson = JsonConvert.DeserializeObject <Car[]>(json, jsonsettings); //Task 4.3 foreach (var Actuator in itemsfromjson) { Actuator.Print(); } } catch (Exception error) { Console.WriteLine($"Error({ error.Message})"); } }
static void Main(string[] args) { try { Kundendaten ersterk = new Kundendaten("Max Mustermann", "Musterweg 15", 1); ersterk.Print(); ersterk.neueNummer(2); ersterk.Print(); Kundendaten zweiterk = new Kundendaten("Ludwig Leiner", "Kikagasse 68", 2); Mitarbeiter ersterm = new Mitarbeiter("Karl Klumpat", "Forstgasse 27", "Elektriker", 1); Mitarbeiter zweiterm = new Mitarbeiter("Toni Toner", "Druckstrasse 87", "Assistent", 2); IPerson[] PersonArray = { ersterk, zweiterk, ersterm, zweiterm, new Kundendaten("Ilse Ilsensberger", "Ilsenweg 30", 3), new Mitarbeiter("Koalrina Karlson", "Karlsonweg 12", "EDV-Technikerin", 3) }; foreach (IPerson Person in PersonArray) { Person.Print(); } var jsonsettings = new JsonSerializerSettings() { Formatting = Formatting.Indented, TypeNameHandling = TypeNameHandling.Auto }; var json = JsonConvert.SerializeObject(PersonArray, jsonsettings); Console.WriteLine(json); File.WriteAllText(@"Person.json", json); string content = File.ReadAllText(@"Person.json"); var itemsfromjson = JsonConvert.DeserializeObject <IPerson[]>(content, jsonsettings); foreach (var Actuator in itemsfromjson) { Actuator.Print(); } } catch (Exception error) { Console.WriteLine($"Error ({error.Message})"); } }