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
新闻热点
疑难解答