zoukankan      html  css  js  c++  java
  • czC#02

    1、out参数

    out参数要求在方法的内部必须为其赋值

    using System;
    using System.Text;
    
    namespace Demo
    {
    
        class Program
        {
            //返回一个数组的最大值,最小值,均值,长度,名称
    
            static void Main()
            {
                int max = 0;
                int min = 0;
                int ave = 0;
                int len = 0;
                string name = "";
                int[] arr = { 1, 4, 10 };
                Test(arr, out max, out min, out ave, out len, out name);
                Console.WriteLine(max);
                Console.WriteLine(min);
                Console.WriteLine(ave);
                Console.WriteLine(len);
                Console.WriteLine(name);
                Console.ReadLine();
    
            }
    
            public static void Test(int[] arr,out int max, out int min, out int ave, out int len, out string name)
            {
                //伪代码
                max = 10;
                min = 1;
                ave = 5;
                len = 3;
                name = "arr";
            }
        }
    
    }

    2、ref参数

    值传递时,原值也会改变

    using System;
    using System.Text;
    
    namespace Demo
    {
    
        class Program
        {
    
            static void Main()
            {
                int num = 10;
                Test(ref num);
                Console.WriteLine(num);
                Console.ReadLine();
    
            }
    
            public static void Test(ref int num)
            {
                num += 10;
            }
        }
    
    }

    3. params可变参数

    参数列表变为数组,方法执行时数组内的元素不可改变

    using System;
    using System.Text;
    
    namespace Demo
    {
    
        class Program
        {
    
            static void Main()
            {
                Console.WriteLine(Test("Linda", 100, 90, 98, 94));
                Console.ReadLine();
    
            }
    
            public static int Test(string name,params int[] score)
            {
                return score[0];
            }
        }
    
    }
  • 相关阅读:
    Python-zip压缩-解压
    使用zabbix监控nginx
    原已经安装好的nginx,现在需要添加一个未被编译安装的模块:
    zabbix 邮件告警配置
    lnmp-zabbix
    Mysql新建用户和数据库并授权
    git标签管理
    Ubuntu下安装tomcat
    git分支管理
    Java拦截器
  • 原文地址:https://www.cnblogs.com/Tanqurey/p/12363930.html
Copyright © 2011-2022 走看看