1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceTemporary8 {9 class PersonTen { One Public classClass1 A { - Public Static voidMethod () - { theConsole.WriteLine ("the static method can be called directly! But it's a very expensive source! "); - } - Public voidMethod1 () - { +Console.WriteLine ("non-static method to create an object to access! "); - } + Public voidMethod2 () A { atMethod1 ();//the method body in the same class can directly access both static and non-static PS: The invocation of a method in a homogeneous way, the method name can be written directly - Method (); - } - } - class Program - { in Static voidMain (string[] args) - { toClass1.method ();//Access static method PS: The invocation of a static method is directly the class name. Method +Class1 obj =NewClass1 ();//Create object PS: A call to a non-static method: Calling a method in another class must be public and the instance name. Method -Obj. Method1 ();//access to a non-static method; the } * } $ }Panax Notoginseng}
Calls to C # methods