+ 6
Why we use static in c#?
static
2 Réponses
+ 5
A class member(method or variable) is declared static so that it can be accessed outside the class using only the class name (no need to create an object)
e.g
class A{
public static int x = 10;
}
class B{
int y = A.x
// as opposed to: A a = new A()
//int y = a.x; if x was not static
}
+ 5
The Static Keyword. In C# terms, “static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the type name instead of a reference or a value, e.g. Guid.NewGuid(). In addition to methods and variables, you can also declare a class to be static
http://theburningmonk.com/2010/07/static-vs-non-static-method-in-csharp/
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members