2011-09-19 60 views
0

这是一段代码,我做了,由于某种原因,当我调用该函数monF视觉工作室给了我以下错误:问题与运行REF功能瓦尔

为“ConsoleApplication1.Program最佳重载的方法匹配.monF(INT [],INT,裁判INT,裁判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); 



     } 
    } 
} 

回答

4

你必须使用调用方法时也ref关键字:

monF(monArray, arraySize, ref monMin, ref monMax); 
+0

非常感谢:)那工作... – ahoura