using System;
class SampleClass
{
public void printOut(string name,int age)
{
Console.Write("名前:" + name);
Console.WriteLine(" 年齢:{0}歳", age);
}
}
class ParamsClass
{
public int ageAvarage(params int[] ages)
{
int sum=0;
foreach(int n in ages)
{
sum+=n;
}
return sum / ages.Length;
}
}
class MainClass
{
static void Main()
{
var sample = new SampleClass();
string name1 = "Kamimura1";
string name2 = "Kamimura2";
string name3 = "kamimura3";
int age1 = 10;
int age2 = 20;
int age3 = 30;
sample.printOut(name1,age1);
sample.printOut(name2, age2);
sample.printOut(name3, age3);
var sample1=new ParamsClass();
int[] ages = { age1, age2, age3 };
Console.WriteLine
("平均年齢:{0}歳",sample1.ageAvarage(ages));
}
}
0 コメント:
コメントを投稿