C#參數(shù)數(shù)列簡(jiǎn)單概述
在向大家詳細(xì)介紹C#參數(shù)數(shù)列之前,首先讓大家了解下C#種的四種參數(shù)形式,然后全面介紹C#參數(shù)數(shù)列。
在微軟的.NET推出后,關(guān)于C#的有關(guān)文章也相繼出現(xiàn),作為微軟的重要的與JAVA抗衡的語(yǔ)言,C#具有很多優(yōu)點(diǎn)。本文將選一些C#語(yǔ)言中的重要知識(shí)詳細(xì)介紹
C#種的四種參數(shù)形式:
◆一般參數(shù)
◆in參數(shù)
◆out參數(shù)
◆C#參數(shù)數(shù)列
本文只介紹C#參數(shù)數(shù)列
C#參數(shù)數(shù)列
C#參數(shù)數(shù)列能夠使多個(gè)相關(guān)的參數(shù)被單個(gè)數(shù)列代表,換就話說,C#參數(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]
【編輯推薦】