zoukankan      html  css  js  c++  java
  • 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 }

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

  • 相关阅读:
    CTF中特别小的EXE是怎么生成的
    递归和动态规划裸题分析
    三次样条插值拟合函数,预测下明后天的疫情
    存储器总结。2019.12.26
    存储器
    江科大计算方法实验
    海明码一篇文章彻底搞懂
    江科大数据库实验
    大数据是什么
    B站自动刷弹幕
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7356823.html
Copyright © 2011-2022 走看看