这是我所做的一段代码,由于某种原因,当我调用函数时,monF visual studio给出了以下错误:
'ConsoleApplication1.Program.monF(int [],int,ref int,ref int)的最佳重载方法匹配'有一些无效的参数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static void monF(int[] a, int size, ref int min, ref int max)
{
min = a[0];
max = a[0];
for (int i = 0; i < size; i++)
{
if (a[i] > max)
{
max = a[i];
}
if (a[i] < min)
{
min = a[i];
}
}
}
static void Main(string[] args)
{
int arraySize = 0;
int monMin, monMax;
Console.WriteLine("Please insert the number of digits you want to compare");
arraySize = int.Parse(Console.ReadLine());
int[] monArray = new int[arraySize];
for (int i = 0; i < arraySize; i++)
{
Console.WriteLine("Please enter number " + i + ": ");
monArray[i] = int.Parse(Console.ReadLine());
}
monF(monArray, arraySize, monMin, monMax);
}
}
}
答案 0 :(得分:4)
调用方法时也必须使用ref关键字:
monF(monArray, arraySize, ref monMin, ref monMax);