public static bool Load(string filename, ref TestTime obj) { FileStream fileStream = null; try { fileStream = File.OpenRead(filename); BinaryFormatter binaryFormatter = new BinaryFormatter(); obj = binaryFormatter.Deserialize(fileStream) as TestTime; } catch (Exception ex) { Console.WriteLine("Исключение: " + ex.Message + " (Будет создан после вызова метода Save)"); return(false); } finally { if (fileStream != null) { fileStream.Close(); } } return(true); }
public static bool Save(string filename, ref TestTime obj) { FileStream fileStream = null; try { fileStream = File.Create(filename); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(fileStream, obj); } catch (Exception ex) { Console.WriteLine("Исключение : " + ex.Message); return(false); } finally { if (fileStream != null) { fileStream.Close(); } } return(true); }