不允许使用默认参数说明符
我有以下代码给出错误
不允许使用默认参数说明符
怎么解决这个问题?
bool listSubscribe(string apikey, string id, string email_address, string [] merge_vars, string email_type="html", bool double_optin=false, bool replace_interests=true, bool send_welcome=false); bool listUnsubscribe(string apikey, string id, string email_address, bool delete_menber=false, bool send_goodbye=true, bool send_notify=true);
根据您的错误消息,您无法在v3.5中执行此操作。
解决方法是多个构造函数:
bool listUnsubscribe(string apikey, string id, string email_address) { return listUnsubscribe(apikey, id, email_address, false, true, true); } bool listUnsubscribe(string apikey, string id, string email_address, bool delete_menber, bool send_goodbye, bool send_notify) { return whatever; }
我刚刚遇到这个错误,我的项目也是针对4.0而不是3.5或更低。
我把它切换到3.5然后再回到4.0然后错误就消失了。 希望这些步骤对您或其他人有用。
应用程序/类库未设置为以.NET 4 Framework为目标。 在项目的设置页面中调整。
可选参数是C#4的一个function,在早期版本中不存在。 由于您使用的是.NET 3.5,因此无法使用可选参数。
切换到.NET 4.0,或使用重载方法。