最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

方法/函數(shù)6(ref參數(shù))

2023-01-26 22:50 作者:此城過客  | 我要投稿

static void Jiangjin(double s)

{ s += 500 ; }

static void Main(string[] args)

{

? ? ? ?double salary = 5000;

? ? ? ?Jiangjin(salary);

? ? ? ?Console.WriteLine(salary);

}

上面這個(gè)語句,按以往的規(guī)則,屬于是錯(cuò)誤的。但是用ref參數(shù),可以改進(jìn)。

static void?Jiangjin(ref?double?s)

{?s += 500 ;?}

static void?Main(string[] args)

{

? ? ? ?double?salary = 5000;

? ? ? ?Jiangjin(ref salary);

? ? ? ?Console.WriteLine(salary);

}

自從加了這個(gè)ref之后,就可以運(yùn)行了。因此ref參數(shù),就相當(dāng)于是連通器,方法里的值改了,

主函數(shù)里是可以通過這個(gè)接收到的。

第二個(gè)例子,交換值:

static void Test(ref int a,ref int b)

{ int temp = a ; a = b ; b = temp ; }

static void Main(string[] args)

{

? ? ? ? int s = 20;

? ? ? ? int w = 10;

? ? ? ? Test(ref s,ref w);

? ? ? ? Console.WriteLine(s);

? ? ? ? Console.WriteLine(w);

}


方法/函數(shù)6(ref參數(shù))的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
道孚县| 济阳县| 特克斯县| 炉霍县| 清远市| 怀仁县| 墨竹工卡县| 虞城县| 盈江县| 雷波县| 贵南县| 聂拉木县| 靖安县| 利津县| 弋阳县| 景洪市| 华坪县| 南木林县| 通城县| 常州市| 讷河市| 大名县| 灌阳县| 瓦房店市| 营口市| 仪征市| 浦江县| 冕宁县| 宁强县| 靖边县| 木兰县| 武穴市| 烟台市| 孝昌县| 左权县| 电白县| 镇康县| 葫芦岛市| 即墨市| 衡阳县| 镇江市|