码迷,mamicode.com
首页 > 其他好文 > 详细

C# params object[] args 可以传多个参数,可以不限制类型(转)

时间:2014-06-10 21:49:32      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:class   ext   get   string   set   cti   

C# params object[] args 可以传多个参数,可以不限制类型

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            print("Information", new Field("Name", "mengyu"), new Field("aa", "bb"));
        }

        static void print(string a, params object[] args)
        {
            Console.WriteLine(a);
            foreach (object obj in args)
            {
                Field field = (Field)obj;
                Console.WriteLine(field.Name + " = " + field.Value);
            }
        }

        class Field
        {
            private string name;
            private string value;

            public Field(string name, string value)
            {
                this.name = name;
                this.value = value;
            }

            public string Name
            {
                get
                {
                    return name;
                }
                set
                {
                    name = value;
                }
            }

            public string Value
            {
                get
                {
                    return value;
                }
                set
                {
                    this.value = value;
                }
            }
        }

    }
}

C# params object[] args 可以传多个参数,可以不限制类型(转),布布扣,bubuko.com

C# params object[] args 可以传多个参数,可以不限制类型(转)

标签:class   ext   get   string   set   cti   

原文地址:http://www.cnblogs.com/coolsundy/p/3779364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!