Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 接收int是无效的表达式错误_C# - Fatal编程技术网

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

C# 接收int是无效的表达式错误,c#,C#,我有一个简单的程序,它接受用户输入,尝试将输入解析为整数,然后将PI舍入为输入值。然而,我有两个错误。一个表示int是无效表达式,另一个表示保存输入值的变量在当前上下文中不存在。有人能向我解释为什么会出现这些错误以及如何修复它们吗 using System; namespace PiToDecimalPlaces{ class Program{ public static void Main(){ //Checks to see if the u

我有一个简单的程序,它接受用户输入,尝试将输入解析为整数,然后将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);
        }
    }
}

我使用的是vs2017,使用的代码如下

Console.WriteLine{0},Roundplaces


它将打印整数值

您正在使用C7功能,但没有使用C7编译器。啊,好的。所以我只需要更新VS?选择您的语言版本为int.TryParseConsole.ReadLine,out int places;是在C7中引入的特性。0@Robert是的,您需要同时更新到Visual Studio 2017,您可以使用int places;int.TryParseConsole.ReadLine,外部位置;