zoukankan      html  css  js  c++  java
  • C#的参数修饰符out,params,ref

    using System;
    
    namespace ParamsProgram
    {
        class TestParams
        {
            public static void Main(string[] args)//static void Main(string[] args)
            {
                int m ;//= 10;
                int[] arr = new int[80];
             for (int i = 0; i < arr.Length; i++)
             {
                 arr[i] = i;
    
             }
                ParamsProgram.TestParams t = new TestParams();
                //t.check(5,6,7,8,9,1);
                
                t.outPara(out m);
                //t.changeNum(m);
                Console.WriteLine(m);
                Console.ReadLine();
            }
            
            public void check(params int[] arr)
            {
                foreach (var i in arr)
                {
                    Console.WriteLine(i);
                }
            }
            public void outPara(out int i)
            { 
                i = 9999;
            }
            public void changeNum(int a)
            {
                a = 100;
            }
        }
    }

    你觉得输出是怎样的呢?

    参数修饰符params,ref,out,

    params 关键字表示的函数的参数是可变的。
    对应于out修饰的参数,不需要初始化也可,即这里使用out时,int m;也可。
    对应于ref修饰的参数,一定要初始化,即这里使用ref时,必须int m=5;初始化参数
    ref 一般侧重于修改,out一般侧重于输出。
  • 相关阅读:
    docker 存储扩容和存放路径修改
    gitlab+jenkins+webhook 代码发布
    jenkins 流水线(pipline)
    kafka单机部署
    nload命令
    jumpserver部署维护
    mysql sleep连接过多的问题解决
    监控zabbix-server本身
    DevOps方案探究
    ceph 存储
  • 原文地址:https://www.cnblogs.com/zhayunjia/p/3583849.html
Copyright © 2011-2022 走看看