[英]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.