Net基础篇_学习笔记_第十天_方法_方法的调用问题

在Main()函数中,调用Test()函数,我们管Main()函数称之为调用者,
管Test()函数称之为被调用者。
如果被调用者想要得到调用者的值:
1)、传递参数。
2)、使用静态字段来模拟全局变量。
如果调用者想要得到被调用者的值:
1)、返回值

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
       public static int _a=8;

        static void Main(string[] args)
        {
            
            int m=Test(_a);
            Console.WriteLine(_a);
            Console.WriteLine(m);
            Console.ReadKey();
        }
        public static int Test(int _a)
        {
            _a = _a + 5;
            return _a;
        }
    }
 1 using System.Collections.Generic;
 2 using System.Linq;
 3 using System.Text;
 4 using System.Threading.Tasks;
 5 
 6 namespace 方法001
 7 {
 8     class Program
 9     { 
10         //写一个方法,判断一个年份是否为闰年
11 
12         static void Main(string[] args)
13         {
14             bool b=IsRun(2016);
15             Console.WriteLine(b);
16             Console.ReadKey();
17         }
18         /// <summary>
19         /// 判断给定的年份是否为闰年
20         /// </summary>
21         /// <param name="year">要判断的年份</param>
22         /// <returns>是否是闰年</returns>
23         public static bool IsRun(int year)
24         {
25             bool b = (year % 400 == 0) ||( year % 4 == 0 && year % 100 != 0);
26             return b;
27         }
28     }
29 }

 一个完整的方法需要注释+方法体。

原文地址:https://www.cnblogs.com/NBOWeb/p/7356823.html