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
Post a Comment