Static Method
Defining static methods is similar to defining non-static methods. When defining static methods, you must add the static keyword before the return value type. When a static method is started, the system creates an instance for the static method in the memory. You do not need to manually go to the static method of the instance. You can directly call the static method by class name, static Methods occupy a certain amount of memory space.
Once a static method is defined in the class, you can directly call the static method through the class name, without the need to instantiate the object to access the static method.
Instance
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace _ 9_StaticMethod
{
Class Program
{
Static void Main (string [] args)
{
Person. GetName ();
}
}
Class Person
{
Public static void GetName ()
{
Console. WriteLine ("My name is sweet ");
Console. ReadKey ();
}
}
}
Running Effect