20, C # inside the creation and display of methods

Source: Internet
Author: User

In C # , and Java are the same, you can create methods. The method described here is the functions, subroutines, processes, etc. in other programming languages.

There are two ways to create a method: one that does not return a value. One is a method that has a return value. Either way, it's really simple.

Example: definition and use of a method without a return value

        Public Static void Main(string[] args)
        {
            Greetings(" Hello, very happy to know you!" ");
            Console.ReadKey(true);
        }
        
        // Create a method with no return value
         Public Static void Greetings(stringText1)
        {
            Console.WriteLine(Text1);
        }

Example: the definition and use of a method that has a return value.

         Public Static void Main(string[] args)
        {
            Console.WriteLine(addition(1,2));
            Console.ReadKey(true);
        }
        // Define a method that returns the sum of two numbers
         Public Static int addition(intNUM1,intnum2)
        {
            return(num1+num2);
        }

Note: You may think that I cite the example is very simple, in fact, the main purpose is to let everyone understand and grasp, and not to let everyone confused. So, it is the purpose to speak clearly.


This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970747

20, C # inside the creation and display of methods

Related Article

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.