What’s the difference between the first and second definitions?
//1
private static string Mask
{
get { return "some text"; }
}
//2
private const string Mask = "some text";
Which benefits has the first and the second approach?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As long as they are private they will probably be optimized to more or less the same code. The re is another story if they are public and used from other assemblies.
constvariables will be substitued/inlined in other assemblies using theconstexpression. That means that you need to recompile every assembly using theconstexpression if you change the expression. On the other hand the property solution will give you a method call overhead each time used.