0

When reading this [ Performance of a static class that stores all strings in one place ] post I wondered if internally to the .NET runtime there is any difference between ie a class member String s_class, a static class member s_static or a String constant s_const?

All of them are immutable and are stored at some place in memory. Is it more efficient to use one or another?

EDIT:

As stated in the comment I would like to know how 'initial' values are handled internally. ie.

public String s1 = "Hello";
public const String s2 = "Hello2";
public static String s3 = "Hello3";

is "Hello" handled different from "Hello2" or "Hello3"?

Community
  • 1
  • 1
Benj
  • 889
  • 1
  • 14
  • 31
  • I have not read the docs but my logic says const should be more efficient, otherwise why should it exist? – bto.rdz Nov 23 '14 at 19:04
  • Any difference when it comes to what? They serve completely different purposes. – Magnus Nov 23 '14 at 19:05
  • @bto.rdz because there are more data types than just string – Benj Nov 23 '14 at 19:08
  • @Magnus difference regarding how the initial values are handles internally. consider ie. String s1 = @"hello"; and const String s2 = @"hello2"; how are "hello" and "hello2" handled internally? as constants? or somewhat different? – Benj Nov 23 '14 at 19:11
  • The answers to the second question in the "Related" links ([What is the difference between const and readonly?](http://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly)) seem to answer your question, except that of course members that are neither `const` nor `readonly` are mutable, even if their type is considered immutable. –  Nov 23 '14 at 19:15

0 Answers0