- Static modifiers
- A static member is a member that is decorated with static
- A static member can only be called by a class
- Classes that are decorated with static are static classes
- A static class cannot be instantiated and can contain only static members and const constants
- A total of five areas in memory
- 1. Heap area-requires programmer to manually open and manage memory
- 2. Stack area-automatic memory management by the system
- 3. Static zone (global Zone)-the data is always present during the sequence operation
- 4. Constant zone-for holding constants
- 5. Code area-the code required to store the program's operation
- Static construction
- The construction method can also be set to static
- Static constructs cannot have parameters and access modifiers
- Static constructs can be used, whether it is a static class or not
- Static constructs are invoked the first time a static member is instantiated or called
-
1 usingSystem;2 3 namespaceStaticclassdemo4 {5 //Static statics6 //a static field, property, or method that can only be called by a class and cannot be called by an instance7 //the process of creating an object using a class is called instantiation, and an object can also be called an instance8 9 //Static ClassTen //in a static class, you can only include static members (fields, properties, methods), const constants One Public Static classA A { - //static fields - Public Static inti; the - //Construction Method - //1. Adding an access modifier before the static construction method - //2. Static construction methods can exist in static classes or in normal classes + //Static Construction Method - //the static construction method will first access the class + /* Public*/ StaticA () A { atConsole.WriteLine ("static construction method of a"); - } - - //Static Methods - Public Static voidTest () - { in //string str = "Li"; - //const int age = N; toConsole.WriteLine ("Test"); + } - } the //2. Static construction methods can exist in static classes or in normal classes * Public classB $ {Panax Notoginseng Public Static intAge ; - //A static construct creates an object and calls it before it is initialized. the StaticB () { +Console.WriteLine ("static construction method of B"); A } the } + class Program - { $ Static voidMain (string[] args) $ { - //a = new A (); - //A.I = ten; the //Console.WriteLine (A.I); - Wuyi //calling a static member directly using the class name theA.I =Ten; - Console.WriteLine (A.I); Wu a.test (); - AboutB.age =Ten; $ -b b =NewB (); - - //a total of five areas in memory A //1. Heap area-requires programmer to manually open and manage memory + //2. Stack area-automatic memory management by the system the //3. Static zone (global Zone)-the data is always present during the sequence operation - //4. Constant zone-for holding constants $ //5. Code area-the code required to store the program's Operation the } the } the}
"Learning notes" C # static Class