I have some experience in developing with Java, Javascript and PHP.
I am reading Microsoft Visual C# 2010 Step by Step which I feel it is a very good book on introducing you to the C# language.
I seem to be having problems in understanding the static keyword. From what I understand this far if a class is declared static all methods and variable have to be static. The main method always is a static method so in the class that the main method exists all variables and methods are declared static if you have to call them in the main method. Also I have noticed that in order to call a static method from another class you do not need to create an object of that you can use the class name.
But what is the actual purpose of the static keyword? When should I declare static variable and methods?
Best Answer
The 'static' keyword in C# is refering to something in the class, or the class itself, that is shared amongst all instances of the class. For example, a field that is marked as static can be accessed from all instances of that class through the class name.
I can honestly say that I have never used a class marked as static with the exception of creating extention methods (Quick tutorial on extension methods).
Anyways, there are specific design patterns for utilizing static methods, such as factory pattern and singleton pattern, but the important thing to remember is that static methods and constructors do not deal with any specific instance of a class (unless you pass one in), typically to do calculations or to do a comparison between objects. The "Main" method you are refering to is always static, but to see it from a different point of view, see this article.
To follow up with this, here is how the difference between static and instantiated methods, fields and properties are called.
Also, check this post out for a deeper look into static classes.