2016-04-11 17 views
-1

些細な質問ですが、結果をコンソールウィンドウに出力するにはどうすればいいですか?そのデータ型をメインに渡す方法を知らない。コンソールウィンドウへの出力

namespace Node 
    { 
     class Program 
     { 
      public static int appLayer(int humData) 
      { 
       int tempData1 = 55; 
       int tempData2 = 60; 
       int tempData3 = 58; 
       int tempData4 = 58; 
       int [] tempData = new int[] {tempData1, tempData2, tempData3, tempData4}; 

       Dictionary<int, int> count = new Dictionary<int, int>(); 
       foreach (int a in tempData) 
       { 
        if (count.ContainsKey(a)) 
         count[a] = count[a] + 1; 
        else 
         count[a] = 1; 
       } 
       int result = int.MinValue; 
       int max = int.MaxValue; 
       foreach (int key in count.Keys) 
       { 
        if (count[key] > max) 
        { 
         max = count[key]; 
         result = key; 
        } 
       } 
       return result; 
      } 
      static void Main(string[] args) 
      { 
       Console.WriteLine("The mode is: " + result); 
      } 
     } 

はあなたに

答えて

1

あなたは)私は今それを得る

 static void Main(string[] args) 
     { 
      var result = appLayer(0); // 0 is the parameter value for humData which is not used so you can remove it... 
      Console.WriteLine("The mode is: " + result); 
      Console.ReadLine(); // Add this to the end to have a pause on the console app 
     }   
+0

をConsole.Read()またはConsole.ReadLineを(あなたのメインの内部メソッドを呼び出して追加する必要があります。迅速かつ明確な説明をありがとう。 – Tom

1
static void Main(string[] args) 
{  
    int result = appLayer(); 
    Console.WriteLine("The mode is: " + result); 
} 

OR

static void Main(string[] args) 
{  
    Console.WriteLine("The mode is: " + appLayer()); 
} 

ありがとうhumDataパラメータであるため、appLayerのプロトタイプが

public static int appLayer() 

次のようになります。次のように私は、コードを持っています 使用されていない。

関連する問題