Q
q.yuhen
Unregistered / Unconfirmed
GUEST, unregistred user!
参数数组
----------------------------------------------------------------
class Class1
{
static void Proc1(string s, params int[] vals)
{
int total = 0;
foreach (int i in vals)
{
total += i;
}
Console.WriteLine(s + total);
}
static void Main(string[] args)
{
Class1.Proc1("Total:", 1, 2, 3, 4, 5, 6);
Class1.Proc1("Total:", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
----------------------------------------------------------------
class Class1
{
static void Proc1(string s, params int[] vals)
{
int total = 0;
foreach (int i in vals)
{
total += i;
}
Console.WriteLine(s + total);
}
static void Main(string[] args)
{
Class1.Proc1("Total:", 1, 2, 3, 4, 5, 6);
Class1.Proc1("Total:", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}