static void DemonstrateReferenceType() { Person myPerson = new Person(); // must use the new keyword to instantiate our type myPerson.Name = "Billy Joe-Bob-Roy"; ManipulatePerson(myPerson); Console.WriteLine("The person's name is: {0}", myPerson.Name); }
/// <summary> /// Because this is a reference type, only the pointer to the memory location is passed /// Thus any manipulation of the data effects the caller, because they point to the same memory location /// /// Think of it this way: If you had very large classes and .NET always made a copy of the whole object anytime you passed it around, /// you would run out of memory pretty quickly. Passing memory pointers around is very efficient. /// </summary> static void ManipulatePerson(Person myPerson) { myPerson.Name = "Jane Doe"; }