输出到控制台window

Output to the console window

小问题,但我如何将结果输出到控制台 window。不知道如何将该数据类型传递给 main。我的代码如下:

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

谢谢

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

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

appLayer的原型应该是

public static int appLayer()

因为没有使用humData参数。

您必须在 main 中调用该方法并添加 Console.Read() 或 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
        }