c# - Error in declaring default parameters for method -


this question has answer here:

i using default parameters i'm getting error

default parameter value 'regularexpression' must compile time constant

here method signature:

public static pipe.datatypes.buyflow.entities.question getemailaddressquestion(string regularexpression = regularexpressions.emailaddressregex, int rank = 1, bool isrequired = true) { } 

and here property:

public static string emailaddressregex {     {             string emailaddressregex = @"^[a-za-z0-9\._%\+\-]+@([a-za-z0-9\-]{1,40}\.)+([a-za-z0-9]{2,4}|museum)$";             return emailaddressregex;         } } 

it error message says. default parameters have constants (at compile time).

the getter of emailaddressregex return different values during runtime. same value not known compiler.

so change emailaddressregex const string compiler error gone.

e.g.

public const string emailaddressregex = @"^[a-za-z0-9\._%\+\-]+@([a-za-z0-9\-]{1,40}\.)+([a-za-z0-9]{2,4}|museum)$"; 

Comments

Popular posts from this blog

many to many - Django Rest Framework ManyToMany filter multiple values -

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

Java Entity Manager - JSON reader was expecting a value but found 'db' -