473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Const in referenced assembly becomes literal in compiled code

I have an issue that I'd like some oone to explain to me. In a C# DLL
I have a several const strings defined as such:

namespace ns
{
public class strings
{
public const string string1 = "XYZ";
public const string string2 = "ABC";
}
}
Now, in another file I have some code like this:

string code = ns.strings.string1;
Now when I compile my code and then disassemble it I see this:

string code = "XYZ";

I understand the compiler could change the reference to the literal
for optimization purposes but the problem then occurs when I change
the code in the DLL and deploy the DLL without recompiling the app,
the change is not picked up in the app because the reference is lost.

Is this by design and is there a way around it?

Apr 6 '07 #1
1 1486
Yes, it is by design. I mean, you are declaring it as a ^constant^
which has a certain implication. If these values can change between
compilation (which means that it definitely is not constant), then you
should make the declaration as public, static, and readonly.

Constant is intended for natural constants, things that will never, ever
change.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sledgehammer777" <mc*****@currentcomm.netwrote in message
news:11*********************@e65g2000hsc.googlegro ups.com...
>I have an issue that I'd like some oone to explain to me. In a C# DLL
I have a several const strings defined as such:

namespace ns
{
public class strings
{
public const string string1 = "XYZ";
public const string string2 = "ABC";
}
}
Now, in another file I have some code like this:

string code = ns.strings.string1;
Now when I compile my code and then disassemble it I see this:

string code = "XYZ";

I understand the compiler could change the reference to the literal
for optimization purposes but the problem then occurs when I change
the code in the DLL and deploy the DLL without recompiling the app,
the change is not picked up in the app because the reference is lost.

Is this by design and is there a way around it?

Apr 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of...
5
by: Lecture Snoddddgrass | last post by:
Back in the old Visual C++ days, it was always important to define constant strings only once so that they wouldn't be stored over and over again in memory. Has .NET resolved this issue? Consider...
10
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
5
by: craig | last post by:
Is it possible to step into the code of a referenced .net assembly from within a project that is being debugged? Thanks!!!
2
by: BH | last post by:
My question may be a bit odd. Right now I can see that all referenced assemblies in my project are compiled into the application assembly so when I deploy the application, I don't see those...
2
by: Ron M. Newman | last post by:
Hello .NET Sages, Question. What is the meaning of adding say, an XML file to a project, next to a .CS file (not that it matters). Does that mean the XML file becomes a part of the compiled...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.