如果一个方法中有两个或多个函数,你会怎么做。我遇到的问题是我需要从 maxminavg 方法返回多个变量,但我不知道如何制作它,因此每个新变量都将值从 maxminavg 方法传送到 main 方法。
static void Main(string[] args)
{
double max = 0d;
double sum = 0d;
double min = arr[0];
double avg = sum / arr.Length;
double avgrnd = Math.Round(avg, 2);
int index1 = 0;
int index2 = 0;
int index3 = 0;
string[] txt = File.ReadLines(@"c: \Users\Stark\Moisture_Data.txt").ToArray();
double[] arr = txt.Select(Double.Parse).ToArray();
print(arr);
Console.WriteLine();
maxminavg(arr, sum, max, min, avg);
Console.WriteLine();
Index(arr, max, min, avgrnd, index1, index2, index3);
Console.ReadLine();
}
public static void maximinavg(double[] arr, double sum, double max, double min, double avg)
{
for (int i = 0; i < arr.Length; i++) {
sum += arr.Length;
if (max < arr[i]) {
max = arr[i];
}
if (min > arr[i]) {
min = arr[i];
}
}
avg = sum / arr.Length;
Console.Write("\nMaximum value in array: {0}, Mimimum value {1}, average value {2}", max, min, avg);
}
public static void Index(double[] arr, double max, double min, double avgrnd int index1, int index2, int index3)
{
for (int i = 0; i < arr.Length; i++)
{
if (max == arr[i])
{
index1 = i;
}
if (min == arr[i])
{
index2 = i;
}
if (avgrnd == arr[1])
{
index3 = i;
}
}
Console.Write("\nMax index {0}, Min index {1}, avg index {2}", index1, index2, index3);
}
HUWWW
相关分类