2016-04-11 11 views
-1

Trivial Frage, aber wie gehe ich über die Ausgabe der Ergebnisse in das Konsolenfenster. Ich weiß nicht, wie ich diesen Datentyp an main weiterleiten soll. Ich habe den Code wie folgt:Ausgabe in das Konsolenfenster

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); 
      } 
     } 

Danke

Antwort

1

Sie haben die Methode in Ihrem Haupt anrufen und fügen Sie eine Console.Read() oder Console.ReadLine()

 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

ich es bekommen. Danke für eine schnelle und klare Erklärung. – Tom

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

ODER

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

Der Prototyp appLayer

public static int appLayer() 

sein sollte, weil die humData Parameter nicht benutzt.

Verwandte Themen