zoukankan      html  css  js  c++  java
  • 参数修饰符 params、 out、ref

    /// <summary>
    /// 参数修饰符 params、 out、ref
    /// </summary>
    using System;

    namespace ConDemo
    {
        class MainClass
        {
            static double Average(params double[] values)
            {
                double average = 0;
                foreach (var item in values) {
                    average+=item;
                }
                average = average / values.Length;
                return average;
            }

            public static void Add(int x, int y, out int ans)
            {
                ans = x + y;
            }

            static void switchIt(ref int x1, ref int x2)
            {
                int x = x1;
                x1 = x2;
                x2 = x;
            }

            /// <summary>
            
    /// The entry point of the program, where the program control starts and ends.
            
    /// </summary>
            
    /// <param name="args">The command-line arguments.</param>
            public static void Main (string[] args)
            {
                Console.WriteLine (Environment.Version);    //4.0.30319.1
                int ans = 0;
                Add (56,  out ans);            //out parameters
                Console.WriteLine (ans);                                            //11
                int x = 3, y = 4;
                switchIt (ref x, ref y);            //ref parameters
                Console.WriteLine ("x={0},y={1}", x, y);            //x=4,y=3
                Console.WriteLine ("{0}", Average (3.0,4.0,5.0));//4

                int i=99;
                object obj = i;                    //box
                obj = 8888;                            //box,  with strong Type!
                Console.WriteLine("i={0}",i);//i=99
                string s = "hello,world.";
                object objs = s;                    //with strong Type!
                objs = "Bonjour!";
                Console.WriteLine(s);    //hello,world.
                Console.ReadKey();
                Console.ReadKey ();
            }
        }
    }
  • 相关阅读:
    raid阵列算法/数据恢复方法汇总
    EMC Isilon(OneFS)误删文件数据恢复过程<存储数据恢复>
    Raid磁盘阵列更换磁盘时另一块盘离线(v7000存储数据恢复)
    SqlServer数据库无法读取的数据恢复方案实施过程
    ds4800服务器lvm信息丢失数据恢复方案
    Hyper-V数据文件丢失数据恢复过程
    v7000存储数据恢复成功率分析-数据恢复初检报告
    Ext4文件系统fsck后损坏如何恢复?-北亚数据恢复
    服务器raid5两块硬盘离线lvm vxfs文件系统数据恢复过程
    临时表
  • 原文地址:https://www.cnblogs.com/flaaash/p/3070801.html
Copyright © 2011-2022 走看看