c#2.0中不允许使用默认参数说明符错误

dap*_*der 1 c# c#-2.0

我在我的程序的代码块中收到此错误.我正在使用c#和.net 2.0.它在代码的第一行中以十进制= 2显示此错误.请帮忙

 private string formatSizeBinary(Int64 size, Int32 decimals = 2)
    {
        string[] sizes = { "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
        double formattedSize = size;
        Int32 sizeIndex = 0;
        while (formattedSize >= 1024 & sizeIndex < sizes.Length)
        {
            formattedSize /= 1024;
            sizeIndex += 1;
        }
        return string.Format("{0} {1}", Math.Round(formattedSize, decimals).ToString(), sizes[sizeIndex]);
    }
Run Code Online (Sandbox Code Playgroud)

Bil*_*egg 5

默认参数在.Net 2中不可用.

它们只在.Net 4.0中可用:

http://msdn.microsoft.com/en-us/library/dd264739.aspx

  • 具体来说,默认参数是在**C#**4中引入的. (4认同)