Rah*_*aki 3 c# static static-methods
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)'
当我将该方法显式声明为静态时,错误就会消失,并且我可以从类声明中删除 static 修饰符,错误就会消失。让我感到困惑的是,我的印象是,当我将类声明为静态时,类中的所有内容都应该自动是静态的,而无需我显式声明它。
让我困惑的是,我的印象是,当我将类声明为静态时,类中的所有内容也应该自动是静态的
静态类的所有成员确实必须是静态的,但这不会自动发生:您必须显式声明所有成员都是静态的。将类声明为静态的目的是让编译器检查所有成员是否都是静态的,并防止任何创建静态类实例的尝试。