C # object-oriented programming for the gentle and newest Learning Series-static method (9)

Source: Internet
Author: User

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

  

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.