编译器错误“不允许使用默认参数说明符”
下面是我的代码。
public class PItem
{
public String content;
public int count;
public int fee;
public int amount;
public string description;
// Default values
public PItem(String _content = "", int _count = 0, int _fee = 0, string _description = "", int _amount = 0)
{
content = _content;
count = _count < 0 ? 0 : _count;
fee = _fee;
description = _description;
amount = _amount < 0 ? 0 : _amount;
}
}
这是在一个班级里面。当我尝试运行程序时,出现以下错误:
不允许使用默认参数说明符
如何解决此错误?
Below is my code.
public class PItem
{
public String content;
public int count;
public int fee;
public int amount;
public string description;
// Default values
public PItem(String _content = "", int _count = 0, int _fee = 0, string _description = "", int _amount = 0)
{
content = _content;
count = _count < 0 ? 0 : _count;
fee = _fee;
description = _description;
amount = _amount < 0 ? 0 : _amount;
}
}
This is inside in a class. When I try to run a program it gives this error:
Default parameter specifiers are not permitted
How can I solve this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是在低于 4 的 C# 版本中不能有可选参数。
您可以在此处找到更多信息。
你可以这样解决:
The problem is that you cannot have optional parameters in C# version less than 4.
You can find more information on this here.
You can solve it like this:
如果您的项目似乎设置为 .NET 4.0,则将其更改为例如 3.5,然后再次更改为 4.0。当我想要将旧解决方案中的类库项目包含到新软件中时,我收到了此错误。两种解决方案都是 .NET 4,但我收到“不允许使用默认参数说明符”错误。我只是做了我所解释的事情。
If your project seems to be set as .NET 4.0 then change it to for example 3.5 and then change to the 4.0 again. I got this error when I included a class library project from my old solution solution to a new one when I wanted to have the project in my new software. Both solutions were .NET 4 but I got "default parameter specifiers are not permitted" error. I just did what I explained.