How is memory allocated when I use:
public class MyClass
{
public const string myEVENT = "Event";
//Other code
}
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.
Well, it’s a compile-time constant – so if you use it from other assemblies, “Event” will be copied into the IL for those other assemblies. Whether that gets interned cross-assembly or not depends on a CLR setting IIRC.
However, if you’re worried about whether you’ll get a new string or a new string variable for each instance of
MyClass, you don’t need to worry –constimpliesstatic.In short, unless you’ve got huge, huge wads of constants (or enormous string constants) it’s not going to cause you an issue.