C# params object[] args 可以传多个参数,可以不限制类型
2007-10-22 09:48
573 查看
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;
}
}
}
}
}
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 可以传多个参数,可以不限制类型
- C# params object[] args 可以传多个参数,可以不限制类型(转)
- C# params object[] args 可以传多个参数,可以不限制类型
- C#的参数类型:params、out和ref
- 问题:C# params类型参数;结果:C#的参数类型:params、out和ref
- c# 泛型 类型参数上的限制(where T:class,new())
- C#中params 关键字可以指定在参数数目可变处采用参数的方法参数
- C#方法的参数 Ref Out Params 4种类型的参数
- c#中out、ref和params的用法与区别 params可以传不定长的参数
- C#的泛型的类型参数可以有带参数的构造函数的约束方式吗
- C# ref、out、params与值类型参数修饰符
- C#方法参数个数和类型相同,名称不同,可以实现重载吗
- C#中ref、out类型参数的区别和params类型参数的用法
- C#方法的参数 Ref Out Params 4种类型的参数
- C#的参数类型:params、out和ref
- C# ref_out_params方法的参数_4种类型的参数
- C#参数类型 params、out和ref
- 非类型模板参数限制——不可以使用内部链接对象
- C#的参数类型:params、out和ref
- C#方法参数个数和类型相同,名称不同,可以实现重载吗