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#

How can you call a class in a class without it being static ie. You can say "Game.Board board = new Game.Board"

You can't say System.Console.WriteLine(Game.length); Why are classes treated differently than variables.

also how come static void Main() { Game.Main(); } doesn't make an infinite loop just curious.

1 Answer

Steven Parker
Steven Parker
231,248 Points

You could write "System.Console.WriteLine(Game.length);" if you have given the class "Game" a static property with the name "length".

Classes are more like types than variables. But variables can hold references to class instances.

And the reason "static void Main() { Game.Main(); }" doesn't make an "infinite loop" is because it eventually crashes after exhausting system resources. Every function or method call uses a bit of memory that is not released until it returns (which this one never does).