public static void BasicClasses() { Console.WriteLine("\nBASIC CLASSES"); // Get input from the user Console.WriteLine("What is your name?"); string name = Console.ReadLine(); // Create instance Person man; // allocate the reference man = new Person(name, Gender.MALE); // allocate the object // PersonsNamespace.Person man = new PersonsNamespace.Person(); man.Greet(); man.AgeAFewYears(10); }
public static void serialize(Person p) { XmlSerializer xmlSerializer = new XmlSerializer(p.GetType()); /*This is known as a resource acquisition statement. It's syntax: using (ResourceType resource = expression) {statement} is identical to: ResourceType resource = expression; try { statement; } finally { if (resource != null) ((IDisposable)resource).Dispose(); } */ Console.WriteLine("Serializing " + p.Name); using ( TextWriter writer = new StreamWriter( Serializer.filepath ) ) /* Streamwriter inherits from the ABSTRACT class, textwriter. The @ sign is a verbatim string literal to ignore escape characters.*/ { xmlSerializer.Serialize(writer, p); } }