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
Accessor methods can be written more efficiently using C# properties. Properties have benefits over accessor 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
then write public getters and
setters that access it indirectly.
0:00
We just learned how to write accessor
methods in the previous video.
0:00
You can imagine this forces you to
write a lot of additional code.
0:05
Two methods for every field.
0:08
Fortunately, C# has some syntactic sugar
that makes it much easier to write
0:11
accessors like these.
0:15
It's called a property.
0:17
We can replace these two
methods with the property.
0:19
I'll write the property down here so
0:21
we can see the differences
between methods and properties.
0:24
First, we give the property
an access modifier.
0:28
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