zoukankan      html  css  js  c++  java
  • C# params object[] args 可以传多个参数,可以不限制类型(转)

    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;
                    }
                }
            }

        }
    }

  • 相关阅读:
    AE二次开发,解决子窗体使用父窗体的AxControl控件
    ArcEngine二次开发中运行出现There is no Spatial Analyst license currently available or enabled.
    Js网站开发学习第一天
    Winform开发1
    MySql安装
    Windows ping加时间戳
    XML特性总结
    linux手册中函数名后小括号中数字的含义
    TCP通信
    swap交换分区概念
  • 原文地址:https://www.cnblogs.com/coolsundy/p/3779364.html
Copyright © 2011-2022 走看看