当我构建我的项目时,VC# 提示不允许使用默认参数说明符。它引导我找到这段代码:
public class TwitterResponse
{
private readonly RestResponseBase _response;
private readonly Exception _exception;
internal TwitterResponse(RestResponseBase response, Exception exception = null)
{
_exception = exception;
_response = response;
}
我的错误是什么?
最佳答案
错误是:
Exception exception = null
您可以转移到 C# 4.0 或更高版本,此代码将编译!
这个问题将帮助你:
C# 3.5 Optional and DefaultValue for parameters
或者您可以在 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;
}
}
关于c# - C# 上不允许出现默认参数说明符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14019083/