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!
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
What is static in static void main(); ? main() is the method, void the blank return type. How about static?
Title says it all.
Having completed C# basics, I've understood ever code I've typed - except that word static. So what is static in the main method header?
Seth Kroger56,412 Points
A static method belongs to the class itself and not an instance. You'll sometimes hear them called class methods. The static keyword allows you to call the method from the class itself without having to create an object instance.
This is particularly useful for
main() because this is the very beginning of the program and you've created no objects yet to call instance methods on.
Ari Misha19,323 Points
Hiya there! A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. Hence you cant create objects on it. I hope it helped. (: