zoukankan      html  css  js  c++  java
  • C#函数的参数传递方式1(值传递与地址传递)

    using System;
    namespace class1
    {
        class program
        {
            static void Main(string[] args)
            {
                //值传递引用,实际参数不会变化
                Console.Write("请输入a=");
                double a = double.Parse(Console.ReadLine());
                Console.Write("请输入b=");
                double b = double.Parse(Console.ReadLine());
                double c = max(a, b);//局部实际参数
                Console.WriteLine("您输入的值中比较大的是{0}", c);
                //地址传递引用,实际参数会变化
                int[] ex = new int[4] { 1, 2, 3, 4 };
                Console.WriteLine("Before");
                foreach (var item in ex)
                {
                    Console.Write("	{0}", item);
                }
                dou(ex);
                Console.WriteLine("
    End");
                foreach (var item in ex)
                {
                    Console.Write("	{0}", item);
                }
            }
            /// <summary>
            /// 值传递
            /// </summary>
            /// <param name="a">形式参数(参数为值类型)</param>
            /// <param name="b">形式参数(参数为值类型)</param>
            /// <returns></returns>
            static double max(double a, double b)
            {//局部形式参数
                double c = a > b ? a : b;
                return c;
            }
            /// <summary>
            /// 地址传递
            /// </summary>
            /// <param name="array">数组参数(参数为引用类型)</param>
            static void dou(int[] array)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = array[i] * 2;
                }
            }
        }
    }

  • 相关阅读:
    Linux and the Unix Philosophy(6)
    在docker环境下部署kafka集群
    Docker学习笔记1-docker介绍及安装
    nginx安装
    centos7下NFS配置
    搭建kafka集群
    nexus开机启动
    java跨库事务Atomikos
    mongodb数据库还原
    Linux下运行jar
  • 原文地址:https://www.cnblogs.com/BruceKing/p/11818590.html
Copyright © 2011-2022 走看看