静态类中的静态方法和非静态类中的静态方法有什么不同?
There is no difference.
Not between the methods anyway.
For the majority of scenarios they are essentially equivalent features. The one notable difference is that only a static
method in a static
class can be an extension method.
There is no difference.
Unlike a non-static class you cannot modify the static method to be an instance method later, because a static class can only contain static members.
This is not allowed and will not compile
public static class Foo{
public void test(){}
}
A static class can contain only static methods, whereas a non-static class can contain both. Deciding which way to go is strictly a design issue in C#.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.