要接受未知數目的參數
當值被傳遞給方法時
下面兩個實例
實例一
實例二
實例一代碼
using System;
using System
using System
using System
namespace ConsoleAppTest
{
public class AddEm {
public static long Add(params int[] args) {
int ctr =
long Total =
for (ctr =
Total += args[ctr];
}
return Total;
}
}
class Program
{
static void Main(string[] args)
{
long Total =
Total = AddEm
Console
Total = AddEm
Console
Total = AddEm
Console
Total = AddEm
Console
Console
}
}
}
實例二代碼
using System;
using System
using System
using System
namespace ConsoleAppTest
{
public class Garbage {
public static void Print(params object[] args) {
int ctr =
for (ctr =
Console
}
}
}
class Program
{
static void Main(string[] args)
{
long ALong =
decimal ADec =
byte Abyte =
string AString =
Console
Garbage
Console
Garbage
Console
Garbage
Console
Garbage
Console
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13747.html