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

        }
    }

  • 相关阅读:
    模拟63 题解
    MYSQL:python 3.x连接数据库的方式
    MYSQL: Starting MySQL….. ERROR! The server quit without updating PID file解决办法
    MYSQL:数据库安装 windows
    Python线程:线程的调度-守护线程
    Visulalization Voronoi in OpenSceneGraph
    Plant Design Review Based on AnyCAD
    Change Line Type in OpenCascade
    Topology and Geometry in OpenCascade-Adapters
    Conversion Operators in OpenCascade
  • 原文地址:https://www.cnblogs.com/coolsundy/p/3779364.html
Copyright © 2011-2022 走看看