2011-09-19 67 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