接收int是无效的表达式错误

时间:2017-10-14 21:58:35

标签: c#

我有一个简单的程序,它接受用户输入,尝试将输入解析为整数,然后将PI舍入到输入的值。但是,我有两个错误。一个说int是一个无效的表达式,另一个表示保存输入值的变量在当前上下文中不存在。任何人都可以向我解释为什么会出现这些错误以及如何修复它们?

using System;

namespace PiToDecimalPlaces{
    class Program{
        public static void Main(){
            //Checks to see if the user input can be parsed into an int data type.  If it can, return the places variable.
            int.TryParse(Console.ReadLine(), out int places);
            Console.WriteLine(Round(places));
        }
        public static decimal Round(int places){
            //Converts the PI value to a decimal, then rounds PI to the number of decimal places given by the user, and returns PI to the number of decimal places.
            return Math.Round((decimal)Math.PI, places);
        }
    }
}

1 个答案:

答案 0 :(得分:-2)

我正在使用vs2017并使用这样的代码

Console.WriteLine( “{0}”,圆形(地方));

,它将打印整数值