2
I was studying here C# until I got to the part about the static
. The teacher shows that it is possible to use this statement in methods and even in the class itself.
The problem is that when using the static
in the class, all methods shall be declared as static
obligatorily. My question is: why should I declare static
in all methods if I already declare that the class is static?
Why can’t the compiler simply set the methods to static implicitly when declaring the class to be static, so you don’t need to add this statement to dozens of methods and attributes like in the example below?
static class Class1 {
static public void Method1(){...}
static public void Method2(){...}
static public void Method3(){...}
}
// Bem melhor a forma abaixo não é ?
static class Class2 {
public void Method1(){...}
public void Method2(){...}
public void Method3(){...}
}