public void saveData() { BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream file = File.Create(pathFile); dataToSave data = new dataToSave(); data.maxScore = maxScore; binaryFormatter.Serialize(file, data); file.Close(); }
void loadData() { if (File.Exists(pathFile)) { BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream file = File.Open(pathFile, FileMode.Open); dataToSave data = (dataToSave)binaryFormatter.Deserialize(file); maxScore = data.maxScore; file.Close(); } else { maxScore = 0; } }