It's hard to work out what you want to know, but hopefully I have got the gist of your question...
Ignoring that that won't compile, and needs a fair number of changes to do what (I suspect) you intended it to, you have got the wrong idea a bit as well.
If I fix your code a little:
class MyClass
{
public string M = " ";
public MyClass(string message)
{
M = message;
}
}
MyClass X;
X = new MyClass(" Hello World! ");
(Which is no where near perfect, but you'll improve it a bit later - I just want to explain what goes where)
The code creates three items on the heap:
1) A string containing a space
2) A sting containing " Hello World! "
3) A class instance of MyClass
When you call the MyClass constructor by using the
new
keyword, the parameter string instance is constructed, and then space is allocated for the class instance, finally it's fields are constructed, so space is allocated for a string containing a space. The code of the constructor is then called and the string field M reference is overwritten with the parameter string reference. (This is hard to explain without pictures, but hopefully you will get the idea).
(And yes, purists, strings are special - let it ride for the moment, ok? Let's not confuse the poor soul!)