zoukankan      html  css  js  c++  java
  • 第一节 49_ref_out 简单

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace _49_ref_out
    {
        class Program
        {
            static void Main(string[] args)
            {
                /* 函数的ref out参数
                 * 函数参数默认的值传递的,也就是"复制一份",例子:
                 * int age = 20;
                 * Int Age(age);
                 * Console.WriteLine("age={0}",age);
                 * ref必须先初始化,因为是引用,所以必须先"有",才能引用,而out则是内部为外部赋值,所以不需要初始化,而且初始化也没用
                 * ref应用的景内部对外部的值进行改变,out则是内部对外部变量的赋值,out一般用在函数有多个返回值的场所
                 * 两个变量的交换 int.TryParse
                */
                int i = 5;
                IncAge(ref i);
                Console.WriteLine("年龄为;{0}",i);
    
                int age=100;
                IncAgeOut(out age);
                IncAgeOut(out age);
                Console.WriteLine("年龄为;{0}", age);
    
    
    
                Console.ReadKey();
    
            }
    
            static void IncAgeOut(out int age) 
            {
                age = 55;
            }
    
            //引用
            static void IncAge(ref int age) 
            {
                age += 5;
            }
        }
    }
    

      

  • 相关阅读:
    11111
    单例-Singleton-03
    单例-Singleton-02
    单例-Singleton-01
    load和initialize
    OC中的static-01
    GCD-06
    GCD-05
    GCD-03
    UIView-01
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2362341.html
Copyright © 2011-2022 走看看