public void savePerson(Person ps) { StreamWriter SW1 = new StreamWriter("../../Person.txt"); SW1.WriteLine("Name: " + ps.Name); SW1.WriteLine("Age: " + ps.Age); SW1.WriteLine("ID: " + ps.Id); SW1.WriteLine("Weight: " + ps.Weight); SW1.WriteLine("Height: " + ps.Height); SW1.Close(); }
static void Main(string[] args) { Program pm = new Program(); string name; int id, age, height, weight; name: Console.WriteLine("What is the name?"); try { name = Console.ReadLine(); } catch (Exception) { Console.Clear(); Console.WriteLine("Wrong answer!"); goto name; } id: Console.WriteLine("What is the ID?"); try { id = int.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); Console.WriteLine("Wrong answer!"); goto id; } age: Console.WriteLine("What is your age?"); try { age = int.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); Console.WriteLine("Wrong answer!"); goto age; } height: Console.WriteLine("What is your height?"); try { height = int.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); Console.WriteLine("Wrong answer!"); goto height; } weight: Console.WriteLine("What is your weight?"); try { weight = int.Parse(Console.ReadLine()); } catch (Exception) { Console.Clear(); Console.WriteLine("Wrong answer!"); goto weight; } Person ps = new Person(id, name, age, height, weight); pm.savePerson(ps); }