Possible Duplicate:
C#.NET – Why do members of a static class need to be declared as static? Why isn't it just implicit?
I am getting an interesting error, in that when I call a method (which I don’t explicitly declare as static) from within a statically declared class, I get a message saying
An object reference is required for the non-static field, method, or property ‘MangoTree.Twitter.OAuthClient.PerformRequest(System.Collections.Generic.Dictionary, string, string, string, MangoTree.Twitter.OAuthClient.RequestType)’
When I explicitly declare the method as static, the error goes away, and I can remove the static modifier from the class declaration and the error stays away. What’s confusing me is that I was under the impression that when I declared the class as static, everything within the class should automatically be static as well, without me having to explicitly declare it so.
All members of a static class must indeed be static, but it is not happening automatically: you must explicitly declare all the members static. The purpose of declaring a class static is to let the compiler perform a check that all members are static, and to prevent any attempt at creating an instance of your static class.