Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default parameter specifiers are not permitted

I have the following code that gives the error

Default parameter specifiers are not permitted

How can this be fixed?

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);
like image 948
Mohammad Azeem Ahmad Avatar asked Oct 19 '11 13:10

Mohammad Azeem Ahmad


3 Answers

Optional parameters are a feature of C# 4, not present in earlier versions. Since you're using .NET 3.5, you can't use optional parameters.

Either switch to .NET 4.0, or use overloaded methods instead.

like image 188
Rik Avatar answered Oct 20 '22 00:10

Rik


As per your error message, you can't do that in v3.5.

The work around is multiple constructors:

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;
}
like image 42
LarsTech Avatar answered Oct 20 '22 01:10

LarsTech


I just now encountered this error and my project is also targeting 4.0 and not 3.5 or below.

I toggled it to 3.5 and then back to 4.0 and then the error went away. Hopefully these steps will work for you, or someone else.

like image 35
wjfamilia Avatar answered Oct 20 '22 01:10

wjfamilia