首页 > 学院 > 开发设计 > 正文

C# Params的使用

2019-11-17 02:46:32
字体:
来源:转载
供稿:网友

C# Params的使用

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表