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#

Static

He may have explained this and I missed it, but what is the "static" keyword all about?

4 Answers

Steven Parker
Steven Parker
231,184 Points

Anything "static" belongs to the class (or type) instead of a specific instance.

The impact of this declaration depends on what it is used on. For example, a static class member would be shared between all instances of a class. But a static class cannot be instantiated.

For more info, see the MSDN page.

OK, so what does 'static' represent here in this method declaration? static void Main();

Steven Parker
Steven Parker
231,184 Points

That's a static member function (method).

Since it's "static", there will only be one of these, and it will exist whether or not the class is ever instantiated. That's particularly important in this case because this is a special method that is called by the system to start the program.

Thank you