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

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -