Your class myString is NOT an immutable class (the way string is) since you
made str1 a public field of class myString (see my previous post with the
complex number example - this would be an immutable class).
I would suspect that if you had read those articles that Jon and I wrote
(posted previously) they will clear up some of your mis-understanding. I'll
try here briefly, but I must insist that you go read Jon's or my articles (I
think mine is more geared toward a beginner to C#, while Jon's uses more
accurate, technical verbage).
However, we can rewrite your example below to do the same thing as you
mentioned in your first post:
public void test(myString astr)
{
astr = new myString ("Hello from testClass"
}
Note that here in my version of test, I am trying to change the VALUE of
astr (which is a reference to a class). Since astr is passed by value, this
has no affect in the calling function. This is what you mentioned doing in
your first post - changing a string in a method, probably as follows:
public void testOP (string mystring)
{
mystring = "new string";
}
In your version (below) you are not changing the value of astr, but rather,
the value of str1 in an instance of myString class. Since both testClass and
theApp reference that same instance, you will see the change both places.
Another note, you might find the following useful on naming conventions, it
will make your code more immediately readable by others (that is, classes
and methods should be capitalized in C#)
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconnamingguidelines.asp