最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解C#中三個(gè)關(guān)鍵字params,Ref,out

 更新時(shí)間:2017年05月19日 11:04:06   作者:RynerLute  
本文主要討論params關(guān)鍵字,ref關(guān)鍵字,out關(guān)鍵字。非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

關(guān)于這三個(gè)關(guān)鍵字之前可以研究一下原本的一些操作

using System;
using System.Collections.Generic;
using System.Text;
namespace ParamsRefOut
{
  class Program
  {
    static void ChangeValue(int i)
    {
      i=5;
      Console.WriteLine("The ChangeValue method changed the value "+i.ToString());
    }
    static void Main(string[] args)
    {
      int i = 10;
      Console.WriteLine("The value of I is "+i.ToString());
      ChangeValue(i);
      Console.WriteLine("The value of I is " + i.ToString());
      Console.ReadLine();
    }
  }
}

觀察運(yùn)行結(jié)果發(fā)現(xiàn)

值并沒有被改變,也就是說此時(shí)的操作的原理可能也是跟以前C語言的函數(shù)操作是一樣的

本文主要討論params關(guān)鍵字,ref關(guān)鍵字,out關(guān)鍵字。

  1)params關(guān)鍵字,官方給出的解釋為用于方法參數(shù)長度不定的情況。有時(shí)候不能確定一個(gè)方法的方法參數(shù)到底有多少個(gè),可以使用params關(guān)鍵字來解決問題。

using System;
using System.Collections.Generic;
using System.Text;
namespace ParamsRefOut
{
  class number
  {
    public static void UseParams(params int [] list)
    {
      for(int i=0;i<list.Length;i++)
      {
        Console.WriteLine(list[i]);
      }
    }
    static void Main(string[] args)
    {
      UseParams(1,2,3);
      int[] myArray = new int[3] {10,11,12};
      UseParams(myArray);
      Console.ReadLine();
    }
  }
}

  2)ref關(guān)鍵字:使用引用類型參數(shù),在方法中對參數(shù)所做的任何更改都將反應(yīng)在該變量中

using System;
using System.Collections.Generic;
using System.Text;
namespace ParamsRefOut
{
  class number
  {
    static void Main()
    {
      int val = 0;
      Method(ref val);
      Console.WriteLine(val.ToString());
    }
    static void Method(ref int i)
    {
      i = 44;
    }
  }
}

  3) out 關(guān)鍵字:out 與ref相似但是out 無需進(jìn)行初始化。

以上所述是小編給大家介紹的C#中三個(gè)關(guān)鍵字params,Ref,out,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

江阴市| 南京市| 婺源县| 衡山县| 龙门县| 香港| 西畴县| 岳阳县| 化隆| 鞍山市| 南丰县| 楚雄市| 辽阳市| 桦甸市| 福安市| 西充县| 乌什县| 柯坪县| 天等县| 巴东县| 芦山县| 安仁县| 南部县| 夏邑县| 辽阳县| 酒泉市| 邵东县| 长岭县| 隆尧县| 蒲城县| 西安市| 尉氏县| 龙江县| 抚宁县| 织金县| 信阳市| 邳州市| 南投县| 靖西县| 休宁县| 大厂|