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 trialJose Perez
1,338 PointsIβm lost!!! Please need help to understand better!! please
What the difference between private read only MapLocation[] _path and Maplocation [] _path = new Maplocation()
I might be wrong in the second example but I just to understand how can we create an array Maplocation if I donβt see anything in the class construct that can support that or can an array be created for any class?
Iβm sorry for the confusing question. I am having a hard time understanding the difference between creating an object and doing the following: private read only MapLocation[] _path; Please help!!!!
Thank you!
1 Answer
Steven Parker
231,236 PointsYou can create an array of any type object, both primitives and classes, just by using the brackets [].
But you have some other differences there, including access modifiers "private" and "read only".
And the code "Maplocation [] _path = new Maplocation()
" would not be valid because it is trying to assign an array with a single item, even though they are the same type.
Maceo Lewis
14,200 PointsMaceo Lewis
14,200 PointsAre you saying that the type can essentially be whatever you want? For example it doesn't have to be string[], double[], int[] etc, but it can be named after a class?
Steven Parker
231,236 PointsSteven Parker
231,236 PointsSure, you can have arrays of class objects. Like the one shown in the example (and in the video).