简体   繁体   English

C#上不允许使用默认参数说明符错误

[英]Default parameter specifiers are not permitted error on C#

When I build my project, VC# says Default parameter specifiers are not permitted. 当我构建项目时,VC#表示不允许使用Default参数说明符。 And it leads me to this code: 它引导我到这个代码:

public class TwitterResponse
{
    private readonly RestResponseBase _response;
    private readonly Exception _exception;

    internal TwitterResponse(RestResponseBase response, Exception exception = null)
    {
        _exception = exception;
        _response = response;
    }

What could be my mistake? 可能是我的错误?

The mistake is: 错误是:

Exception exception = null

You can move to C# 4.0 or later, this code will compile! 你可以转到C#4.0或更高版本,这段代码将被编译!

This question will help you: 这个问题可以帮到你:

C# 3.5 Optional and DefaultValue for parameters C#3.5参数的Optional和DefaultValue

Or you can make two overrides to solve this on C# 3.0 or earlier: 或者您可以在C#3.0或更早版本上进行两次覆盖以解决此问题:

public class TwitterResponse
{
    private readonly RestResponseBase _response;
    private readonly Exception _exception;

    internal TwitterResponse(RestResponseBase response): this(response, null)
    {

    }

    internal TwitterResponse(RestResponseBase response, Exception exception)
    {
        _exception = exception;
        _response = response;
    }
}

This could happen if you are using .NET 3.5. 如果您使用的是.NET 3.5,则可能会发生这种情况 Optional parameters were introduced in C# 4.0. 可选参数在C#4.0中引入。

internal TwitterResponse(RestResponseBase response, Exception exception = null)
{
    _exception = exception;
    _response = response;
}

Should be: 应该:

internal TwitterResponse(RestResponseBase response, Exception exception)
{
    _exception = exception;
    _response = response;
}

Note how there is no default value for the exception variable. 请注意exception变量没有默认值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:不允许使用默认参数说明符 - Error: default parameter specifiers are not permitted C#桌面应用程序中不允许使用默认参数说明符 - Default parameter specifiers are not permitted in c# desktop application 如何使用Framework 3.5消除C#中的此错误此错误出现不允许使用默认参数说明符 - How to remove this error in C# with framework 3.5 this error come Default parameter specifiers are not permitted 不允许使用默认参数说明符 - Default parameter specifiers are not permitted 编译器错误“不允许使用默认参数说明符” - Compiler error “Default parameter specifiers are not permitted” 使用Jenkins MSBuild的.NET生成错误“不允许使用默认参数说明符” - .NET build using Jenkins MSBuild error “Default parameter specifiers are not permitted” .Net 4.0- Project出现编译错误“不允许使用默认参数说明符” - Compile Error “Default parameter specifiers are not permitted” with .Net 4.0- Project 是否可以解决.Net 3.5中的“不允许使用默认参数说明符”错误? - Is it possible to work around the “Default parameter specifiers are not permitted” error in .Net 3.5? Mod_Color.cs(55,55):错误CS0241:不允许使用默认参数说明符(CS0241)(Assembly-CSharp) - Mod_Color.cs(55,55): Error CS0241: Default parameter specifiers are not permitted (CS0241) (Assembly-CSharp) c#中有哪些访问说明符? 什么是默认值? - What are the access-specifiers available in c#? What is the default one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM