Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • what do you mean by "better"? Commented Sep 23, 2015 at 9:26
  • better in terms of memory usage and performance? Commented Sep 23, 2015 at 9:28
  • 4
    You've already observed that the generated IL is identical, clearly the performance of identical IL is identical. "Better" in programming can also mean easier on you Commented Sep 23, 2015 at 9:44
  • 2
    Consider this: You continue writing, with "Hello" used all over your class. Next week, you are asked for a Spanish version, so you have to replace "Hello" with "Hola" everywhere, vs once in the constant Commented Sep 23, 2015 at 10:10
  • 7
    You are micro-optimising. Is your app running too slowly, or using too many resources? If so, profile it, identify the problems and fix them. Until then, write easy-to-read and maintain code. As @Caleth says, the only thing you should be considering at this stage is whether the string is used more than once. If it is, make it a constant. If it needs to support more than one language, make it a resource. To reiterate: absolutely do not try to outsmart the compiler at this sort of level by worrying about speed and memory. Commented Sep 23, 2015 at 10:13