static void Main(string[] args) { Console.WriteLine("***** DEMO: Understanding Object Serialization *****"); JamesBondCar jbc = new JamesBondCar(); jbc.CanFly = true; jbc.CanSubmerge = false; jbc.TheRadio.StationPresets = new double[] { 89.3, 105.1, 97.1 }; jbc.TheRadio.HasTweeters = true; PrintJamesBondCar(jbc); // Binary string fileName = "Anna.dat"; SaveAsBinaryFormat(jbc, fileName); JamesBondCar jbcLoad = LoadFromBinaryFile(fileName); PrintJamesBondCar(jbcLoad); //JSON string jsonFileName = "Anna.txt"; Employee empDetails = new Employee { FirstName = "Anna", LastName = "Hakobyan", Address = new Address { Country = "Armenia", State = "Yerevan", ZipCode = "895578" }, EmployeeId = "189811211", Test = new Dictionary <string, int>() }; empDetails.Test.Add("7", 9); empDetails.Test.Add("2", 3); empDetails.Test.Add("8", 9); empDetails.Test.Add("12", 56); SaveAsJsonFormat(empDetails, jsonFileName); Employee fakeEmployeFromJSON = LoadFromJSONFile(jsonFileName); PrintEmployee(fakeEmployeFromJSON); Console.ReadLine(); }
static void PrintJamesBondCar(JamesBondCar jbc) { if (jbc == null) { return; } Console.WriteLine("***** Print JamesBondCar type *****"); Console.WriteLine($" CanFly: {jbc.CanFly}"); Console.WriteLine($" CanSubmerge: {jbc.CanSubmerge}"); Console.Write($" TheRadio.StationPresets: "); foreach (var station in jbc.TheRadio.StationPresets) { Console.Write($"{station}; "); } Console.WriteLine(); Console.WriteLine($"TheRadio.HasTweeters: {jbc.TheRadio.HasTweeters}"); }