C# static | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# static

What is the static command for? Why isn't it used when I want to declare a method inside a class?

10th Jan 2023, 11:09 AM
Giovanni Paolo Balestriere
Giovanni Paolo Balestriere - avatar
1 Answer
+ 1
Static means that the compiler gives the item a unique, fixed location in memory that never moves. It is not dynamically allocated or replicated at run time. A static object does not need a constructor, since there is one instance already defined in a fixed location in memory. A static variable inside a function holds its value from one call to the next, since no other portions of the code would re-use that memory.
10th Jan 2023, 8:32 PM
Brian
Brian - avatar