using System;namespace Params{ class PRogram { static void Main(string[] args) { PrintMany("Hello", "World"); } static void PrintMany(params object[] allParams) { if(allParams != null) { foreach(var p in allParams) { Console.WriteLine(p); } } Console.Read(); } }}
輸出結果:
HelloWorld
Params在你不知道參數的數量時顯得很有用,雖然也可以使用List等集合代替,但是使用Params顯得更直觀不是嗎?
轉載聲明:本文轉載至http://www.zhoumy.cn,原文鏈接:http://www.zhoumy.cn/?id=6
新聞熱點
疑難解答