Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Encapsulation with Properties Accessor Methods

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Confuse about naming parameter in Setter that use word value.

I just want to know that why we need to use word value instead of normal word, because the word value is a keyword not the normal text that we use to name things. Is there something special in order to name parameter in Setter method? Thank you in advance

2 Answers

Steven Parker
Steven Parker
231,269 Points

The word "value" is not a reserved word in C#.

You may be thinking of how it is a contextual keyword in the set accessor of property declarations..

But here, it is just an ordinary name for a variable, but a good choice for the name of the parameter passed to a setter method.

Thanitsak Leuangsupornpong
Thanitsak Leuangsupornpong
7,490 Points

Thank You very much for the answer! But in the property or auto-property we need to use value keyword for setter right? So that it can store value like variable as teacher said.

Steven Parker
Steven Parker
231,269 Points

Right. As I said, when working with properties, the name "value" is what is known as a contextual keyword.

Evan Welch
Evan Welch
1,815 Points

I'm reading here because I am having trouble figuring how one value could be enough information for a location which needs a x, y, and map argument. After all MapLocation(int x, int y, Map map) needs three arguments x, y, and map.

Thank you for any help!

Steven Parker
Steven Parker
231,269 Points

You may be confusing constructor parameters (like "int x, int y, Map map") with a set accessor value.

You can have any number of constructor parameters.