+ 2

What does 'static' mean? And, what does it do?

Can you please tell me what does static mean and what it does? I'm still learning and I didn't undertand that. Thanks :)

7th Jan 2017, 11:19 PM
Claudio González
Claudio González - avatar
5 ответов
+ 7
Normally, if you have class Person { int age; string name; public void SayHi() { Console.WriteLine("Hi"); } } You can then declare an object and use the class methods against that object: Person customer = new Person; customer.SayHi(); //outputs "Hi" But if you have a static class, you access the methods and members of the class itself, and you cannot create (or "instantiate") objects using that class: static class Person { int age; string name; public void SayHi() { Console.WriteLine("Hi"); } } Person.SayHi() // outputs "Hi" Person customer = new Person; // generates an error!
8th Jan 2017, 2:02 PM
Myk Dowling
Myk Dowling - avatar
+ 4
Static is a variable and a function that has a scope and a lifetime associated with the container program.
3rd Feb 2017, 10:23 PM
CHUN
+ 3
Static makes the members of the clases belog to inself, insteand of beloning to individual object. For example if you define a class Animal with the variable count, there alwas be only one no matter how many animals objets you instantiens, otherwise you goin to create a variable for each objet you crate with this class.
7th Jan 2017, 11:57 PM
Alfonso Alejandro Rodriguez Nolasco
+ 1
if you are set the value same for all you declare that variable as static
18th Jan 2017, 3:49 AM
prasanna kumar
prasanna kumar - avatar
+ 1
static is a keyword if the value is same for all then declare a variable as static if you create the method as static then we cannot create object you can directly access by using class name
4th Feb 2017, 1:38 AM
prasanna kumar
prasanna kumar - avatar