首页 > 解决方案 > 在控制台应用程序中打印从我的代码返回的值

问题描述

我正在尝试在我的控制台应用程序中显示计算结果。所以它将发送这个类

namespace The_Code_Challenge
{
    class HeatCalculator
    {
        public static decimal ActualHeatRate(decimal TotalHeatInput, decimal ActualNetGeneration, GeneratorType generatorType)
        {
            return TotalHeatInput / ActualNetGeneration;
        }
    }
}

到我的主要

namespace The_Code_Challenge
{
    class MyClassCS
    {
        static void Main()
        {
            FileWatch.Initialize();
        }
    }
}

我的问题是:我如何在我的main? 以及如何显示我的结果?

标签: c#returnconsole-application

解决方案


你需要使用Console.WriteLine().

您的课程HeatCalculator必须是公开的。

HeatCalculator calc = new HeatCalculator(); Console.WriteLine(calc.ActualHeatRate(1,2,generatorType));

希望它能回答你的问题。


推荐阅读