Joey Callisay <(E-Mail Removed)> wrote:
> But passing a string by value and changing the value of that string on the
> receiving method will not change the original string.
> Unlike passing the dataset by value, isn't it Mr. Skeet?
No, because you *can't* change the "value of that string". Note that
there's a big difference between changing the data within an object and
changing the value of a reference type variable. For instance, these
two methods are similar:
public void TryToChangeString (string x)
{
x = "hello";
}
public void TryToChangeDataSet (DataSet ds)
{
ds = new DataSet();
}
These two methods *aren't* similar:
public void TryToChangeString2 (string x)
{
x = "hello";
}
public void TryToChangeDataSet2 (DataSet ds)
{
ds.AcceptChanges();
}
The important thing to realise is that you never actually pass a
DataSet or a string, either by reference or by value - you pass a
*reference* to a DataSet or a string, and you can pass that reference
by reference or by value.
There's nothing special going on here - it's just the way reference
types work, and it's the same for both String and DataSet - the only
difference is that there happens to be no way of changing the contents
of a String. That's not .NET "including handling" of String in a
special way - you can write your own types which behave exactly the
same way, just by not providing any members which can change the data
in the object.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too