C# 输出到控制台窗口
这个问题很简单,但我如何将结果输出到控制台窗口呢。不知道如何将该数据类型传递给main。我的代码如下:C# 输出到控制台窗口,c#,console-application,C#,Console Application,这个问题很简单,但我如何将结果输出到控制台窗口呢。不知道如何将该数据类型传递给main。我的代码如下: namespace Node { class Program { public static int appLayer(int humData) { int tempData1 = 55; int tempData2 = 60;
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);
}
}
名称空间节点
{
班级计划
{
公共静态int-appLayer(int-humData)
{
int tempData1=55;
int tempData2=60;
int tempData3=58;
int tempData4=58;
int[]tempData=newint[]{tempData1,tempData2,tempData3,tempData4};
字典计数=新字典();
foreach(tempData中的int a)
{
如果(计算容器(a))
计数[a]=计数[a]+1;
其他的
计数[a]=1;
}
int result=int.MinValue;
int max=int.MaxValue;
foreach(count.Keys中的int键)
{
如果(计数[键]>最大值)
{
最大值=计数[键];
结果=键;
}
}
返回结果;
}
静态void Main(字符串[]参数)
{
Console.WriteLine(“模式为:“+result”);
}
}
多谢各位
static void Main(string[] args)
{
int result = appLayer();
Console.WriteLine("The mode is: " + result);
}
或
appLayer
的原型应该是
public static int appLayer()
因为未使用
humData
参数。您必须在main中调用该方法并添加Console.Read()或Console.ReadLine()
我现在明白了。谢谢你快速清晰的解释。
public static int appLayer()
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
}