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 trialIlya Sikharulidze
Courses Plus Student 1,073 PointsPath _path
I don't understand why do we have: private readonly Path _path Can someone please explain! And also, why when we create "Invader" constructor we write: Invader(Path path) ?
1 Answer
Steven Parker
231,268 PointsLet's break that down:
- private this will only be available to code inside the class
- readonly after the instance is created, it cannot be changed
- Path it is an item of type "Path"
- _path and it's name is "
_path
"
And when you create an instance, you pass the Path to the constructor, which is why it has that parameter. Inside the constructor, the field value is set ("_path = path;
"), and it will be permanent for the life of the instance.
Cristina Rosales
10,929 PointsCristina Rosales
10,929 Pointsdoes it read as private readonly Path _path' because we are using _path as the attribute name and the argument name from the constructor?
would private readonly Path _path = _path; technically work (is what's going on under the hood) aswell?