小编cir*_*ark的帖子

C# 传递一个带有可选默认值的整数变量

class Program
{
    static void Main(string[] args)
    {
        WriteLine("What is the radius of your circle: ");
        WriteLine("The area of your circle is: " + 
            circleArea(Double.Parse(ReadLine())).ToString());
        ReadKey();
    }

    static double circleArea(double radius = 5.00)
    {            
        return Math.PI * (radius * radius);
    }
}
Run Code Online (Sandbox Code Playgroud)

我以为我已经正确设置了;但是,我收到 System.FormatException 错误:'输入字符串的格式不正确。在WriteLine("The area of your circle is: " + circleArea(Double.Parse(ReadLine())).ToString());没有输入值的情况下就行。我希望它的默认值为 2。谢谢。

c# default optional

5
推荐指数
1
解决办法
223
查看次数

标签 统计

c# ×1

default ×1

optional ×1