Delegates - Value Type or Reference Type?

  • Thread starter Thread starter Smithers
  • Start date Start date
S

Smithers

Are delegates value types or reference types? I was just pondering the fact
that delegates are immutable... Does this mean that they are value types and
not reference types?

Thanks.
 
strings are immutable also and they are not value types.
delegates are not value types. they can be null :-)
 
Smithers said:
Are delegates value types or reference types? I was just pondering the fact
that delegates are immutable... Does this mean that they are value types and
not reference types?

No, they are a reference type.

Immutable doesn't mean it has to be a value type. And something that is
a value type is not required to be immutable. The two often go
hand-in-hand, but they are not actually the same thing, and there are in
fact counter-examples of each in the .NET Framework (the String class,
for example).

Pete
 
Peter Duniho said:
No, they are a reference type.

Immutable doesn't mean it has to be a value type. And something that is
a value type is not required to be immutable. The two often go
hand-in-hand, but they are not actually the same thing, and there are in
fact counter-examples of each in the .NET Framework (the String class,
for example).

The difference being that while immutable reference types are
reasonably common and perfectly reasonable, making value types mutable
is almost *always* a bad idea, and can result in some very confusing
behaviour!
 

Peter:
I still miss the copy-on-write semantics for strings I loved in Delphi.
While I know C# and even .NET says strings are immutable,
Do you know if the CLR treats strings as smart?

I hope Nicholas Paldino reads this, as he'd be sure to know. =)
The difference being that while immutable reference types are
reasonably common and perfectly reasonable, making value types mutable
is almost *always* a bad idea, and can result in some very confusing
behaviour!

Hmm. Give me an example of when it would be almost a good idea. =)

- Michael Starberg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top