Re: Datasets? Properties? Values?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/20/04


Date: Fri, 20 Aug 2004 08:57:40 +0100

Cor Ligthert <notfirstname@planet.nl> wrote:
> > Not really. There's nothing special about string here. It's just an
> > immutable object, like any other immutable object one could design.
> >
> > There *are* ways in which the CLR treats strings in a special manner,
> > but this isn't one of them.
>
> What do I miss?
>
> In my opinion is the reason is from the behaviour is that the string is
> passed by its value of the pointer to its starting adres and by a change get
> a new pointer.
>
> While the dataset keeps its own pointer

No, DataSet doesn't "keep its own pointer". In both cases, they're just
reference types. You can't change the contents of a string, you can
change the contents of a DataSet. In both cases, changing the value of
a variable won't change the object though. In other words:

DataSet x = GetSomeDataSet();
x = GetSomeOtherDataSet();

doesn't change either DataSet - it just changes the value of x from a
reference to one DataSet to a reference to another DataSet.
 
> Your answer is therefore not wrong, however I would not completly answer it
> like you do. There is something special to the string, it is immutable and
> therefore it gets evertime a new pointer.

But being immutable has nothing to do with the CLR. You can write your
own immutable classes which behave exactly the same way.

> As we disscussed before not all systems have immutable strings, so you may
> call this something "special" from Net. (And let us not discuss about the
> word special, maybe is not immutable at the moment "special").
>
> Correct me when I am "completly" wrong?

What's wrong is the impression that strings are handled differently to
other types in this respect. They're not at all. String is a reference
type which happens to be immutable. The immutability just means there
isn't any way to change the contents of the object, but that doesn't
mean the CLR handles it differently or anything like that. (Not in this
respect, anyway - interning etc is a different matter.)

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Why doesnt Integer have a setValue(int i), and is there a way of changing its value.
    ... The alternative to immutability would ... password "guest" as Strings to some function and then at some later ... username String to "root". ... this has the potential of being a security problem. ...
    (comp.lang.java.programmer)
  • Re: Why String is Immutable?
    ... >>> secret behind Java's very fast substring implementation.'' ... It seems to me that a mutable string could exhibit ... >>>this these as advantages of immutability. ...
    (comp.lang.java.programmer)
  • Re: Datasets? Properties? Values?
    ... There's nothing special about string here. ... >> immutable object, like any other immutable object one could design. ... > passed by its value of the pointer to its starting adres and by a change get ... The immutability just means there ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Datasets? Properties? Values?
    ... There's nothing special about string here. ... >> immutable object, like any other immutable object one could design. ... > passed by its value of the pointer to its starting adres and by a change get ... The immutability just means there ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Datasets? Properties? Values?
    ... There's nothing special about string here. ... >> immutable object, like any other immutable object one could design. ... > passed by its value of the pointer to its starting adres and by a change get ... The immutability just means there ...
    (microsoft.public.dotnet.general)