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 trialJames Hammond
1,297 PointsHow do I get a list from an array from a separate class to bring on Console.WriteLine?
I am working on a Console Starbucks Experience, where a customer comes in and is shown a menu. I have a Menu class, a Program Class, and a Customer Class.
right now the menu class has an array of items the customer can buy. As I am learning though, I am wondering how I would print the information of the array in the Menu Class onto the screen in the program class.
2 Answers
Steven Parker
231,169 PointsThere are a number of possible ways this could happen, including:
- the program class could contain an instance of the menu class
- an instance of the menu class might be passed to the program class
- the menu class might be static
- the array inside the menu could be publicly accessible and printed by code in the program class
- the menu class might have a method that prints out the array when invoked
Alexander La Bianca
15,959 PointsYou would 'import' the class into your Program class. And then instantiate a menu object. Like
Menu menu1 = new Menu(); //pass in whatever is required in your constructor