//在一個方法中,返回多個不同型別的返回值
//在呼叫前,out引數只定義不賦值,在方法中,必須為out引數賦值
static void Main(string[] args)
{
int[] num = { 1, 2, 3, 4, 5 };
int max;
int min;
double avg;
GetMaxMinAvg(num, out max, out min, out avg);
Console.WriteLine("{0},max是{1},min是{2},avg是{3}", num, max, min, avg);
Console.ReadKey();
}
public static void GetMaxMinAvg(int[] num, out int max, out int min, out double avg)
{
min = num[0];
max = num[0];
int sum = 0;
for (int i = 0; i < num.Length; i++)
{
if (max < num[i])
{
max = num[i];
}
if (min > num[i])
{
min = num[i];
}
sum += num[i];
}
avg = (double)sum / num.Length;
}