private void btnSavePersist_Click(object sender, System.EventArgs e) { if (this.mCountry != null) { FileStream fs = null; try { PersistedCountry pc = new PersistedCountry( this.mCountry.Name, this.mCountry.Population); fs = File.Create(Application.StartupPath + COUNTRY_FILE); pc.Save(fs); } finally { fs.Close(); } } }
private void btnLoadPersist_Click(object sender, System.EventArgs e) { FileStream fs = null; try { PersistedCountry pc = new PersistedCountry(string.Empty, 0); fs = File.Open(Application.StartupPath + COUNTRY_FILE, FileMode.Open); pc.Load(fs); this.mCountry = new ImprovedCountry(pc.Name, pc.Population); this.txtName.Text = this.mCountry.Name; this.txtPopulation.Text = this.mCountry.Population.ToString(); } finally { fs.Close(); } }