zoukankan      html  css  js  c++  java
  • 关于方法的ref

    没有ref的方法时:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication7
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             int number = 10;
    14             Test(number);
    15             Console.WriteLine(number);//输出结果还是10,方法并没有改变number的值
    16             Console.ReadKey();
    17         }
    18 
    19         static int Test(int a)
    20         {
    21             a = 100;
    22         }
    23         
    24     }
    25 }

    有ref的方法时://ref 双向传递值

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication7
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             int number = 10;
    14             Test(ref number);
    15             Console.WriteLine(number);//输出结果是100,方法改变了number的值
    16             Console.ReadKey();
    17         }
    18 
    19         static int Test(ref int a)
    20         {
    21             a = 100;
    22         }
    23         
    24     }
    25 }
  • 相关阅读:
    application , application pool., W3wp ,httpapplication, domain
    HDFS
    spark
    Hive
    container docker
    Azure&& hdinsight
    Native Code
    拥抱重构
    六个重构方法可帮你提升80%的代码质量
    重构 小步进行曲
  • 原文地址:https://www.cnblogs.com/start-from-scratch/p/5057005.html
Copyright © 2011-2022 走看看