国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > 綜合 > 正文

C#重點(diǎn)知識(shí)詳解(一)

2024-07-21 02:20:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
前沿

在微軟的.net推出后,關(guān)于c#的有關(guān)文章也相繼出現(xiàn),作為微軟的重要的與java抗衡的語(yǔ)言,c#具有很多優(yōu)點(diǎn)。本文將選一些c#語(yǔ)言中的重要知識(shí)詳細(xì)介紹,

第一章:參數(shù)

1。1 in 參數(shù)

c#種的四種參數(shù)形式:
一般參數(shù)
in參數(shù)
out參數(shù)
參數(shù)數(shù)列
本章將介紹后三種的使用。

在c語(yǔ)言你可以通傳遞地址(即實(shí)參)或是delphi語(yǔ)言中通過(guò)var指示符傳遞地址參數(shù)來(lái)進(jìn)行數(shù)據(jù)排序等操作,在c#語(yǔ)言中,是如何做的呢?"in"關(guān)鍵字可以幫助你。這個(gè)關(guān)鍵字可以通過(guò)參數(shù)傳遞你想返回的值。
namespace testrefp
{
using system;
public class myclass
{

public static void reftest(ref int ival1 )
{
ival1 += 2;

}
public static void main()
{
int i=3; //變量需要初始化

reftest(ref i );
console.writeline(i);

}
}
}

必須注意的是變量要須先初始化。

結(jié)果:

5



1。2 out 參數(shù)


你是否想一次返回多個(gè)值?在c++語(yǔ)言中這項(xiàng)任務(wù)基本上是不可能完成的任務(wù)。在c#中"out"關(guān)鍵字可以幫助你輕松完成。這個(gè)關(guān)鍵字可以通過(guò)參數(shù)一次返回多個(gè)值。
public class mathclass
{
public static int testout(out int ival1, out int ival2)
{
ival1 = 10;
ival2 = 20;
return 0;
}

public static void main()
{
int i, j; // 變量不需要初始化。
console.writeline(testout(out i, out j));
console.writeline(i);
console.writeline(j);
}
}

結(jié)果:

0 10 20

1。3 參數(shù)數(shù)列

參數(shù)數(shù)列能夠使多個(gè)相關(guān)的參數(shù)被單個(gè)數(shù)列代表,換就話(huà)說(shuō),參數(shù)數(shù)列就是變量的長(zhǎng)度。

using system;

class test
{
static void f(params int[] args) {
console.writeline("# 參數(shù): {0}", args.length);
for (int i = 0; i < args.length; i++)
console.writeline("/targs[{0}] = {1}", i, args[i]);
}

static void main() {
f();
f(1);
f(1, 2);
f(1, 2, 3);
f(new int[] {1, 2, 3, 4});
}
}

以下為輸出結(jié)果:

# 參數(shù): 0
# 參數(shù): 1
args[0] = 1
# 參數(shù): 2
args[0] = 1
args[1] = 2
# 參數(shù): 3
args[0] = 1
args[1] = 2
args[2] = 3
# 參數(shù): 4
args[0] = 1
args[1] = 2
args[2] = 3
args[3]
  • 本文來(lái)源于網(wǎng)頁(yè)設(shè)計(jì)愛(ài)好者web開(kāi)發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問(wèn)。
  • 發(fā)表評(píng)論 共有條評(píng)論
    用戶(hù)名: 密碼:
    驗(yàn)證碼: 匿名發(fā)表
    主站蜘蛛池模板: 阜宁县| 怀来县| 阜南县| 兴国县| 全南县| 商洛市| 隆子县| 同心县| 巧家县| 望奎县| 巴里| 南通市| 十堰市| 博爱县| 澄迈县| 阿城市| 湛江市| 榆中县| 青河县| 玉龙| 康马县| 瑞丽市| 闵行区| 通城县| 永丰县| 满洲里市| 扬中市| 子洲县| 涡阳县| 洞口县| 德江县| 福安市| 五华县| 宁陕县| 罗平县| 周口市| 丁青县| 江北区| 望奎县| 松原市| 明水县|