Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed C# Objects!
You have completed C# Objects!
Preview
Properties can be used the same way fields are, but they're really more like methods.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Right now, we don't have anything
that sets the location property.
0:00
The default value of an uninitialized
map location is null.
0:02
We don't want users of the invader
class getting null when they ask for
0:06
the invader's location.
0:09
We need to initialize it to some starting
value when the object's created.
0:10
That's the purpose of the constructor.
0:14
So let's add a constructor.
0:16
So we'll type public Invader.
0:19
The constructor will set
the location property to the first
0:22
location on the path.
0:24
So the constructor needs
to have the path passed in.
0:26
We'll get the GetLocation method of the
path object to get the first location on
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up