#42 – Interacting with an Object

Once you create an instance of a reference type using the new keyword, you can interact with the new object through the variable that serves as a reference to that object.  You can call the object’s methods or read and write its properties.

 // Make a new Person object
 Person p1 = new Person("Sean", 46);

 // Read some properties
 string theName = p1.Name;   // Sean
 int howOld = p1.Age;        // 46

 // Set Age property to new value
 p1.Age = p1.Age - 10;
 int younger = p1.Age;       // Now 36

 // Call method that takes no parameters, returns description
 //   Will return:  Sean is 36 yrs old.
 string describe = p1.Description();

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 43 other followers