By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Delegates - Value Type or Reference Type?

P: n/a
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.
Sep 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
strings are immutable also and they are not value types.
delegates are not value types. they can be null :-)

"Smithers" <A@B.comwrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...
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.
Sep 26 '07 #2

P: n/a
Smithers wrote:
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
Sep 26 '07 #3

P: n/a
Peter Duniho <Np*********@NnOwSlPiAnMk.comwrote:
Smithers wrote:
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).
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!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '07 #4

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Peter Duniho <Np*********@NnOwSlPiAnMk.comwrote:
>Smithers wrote:
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).
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. =)
--
Jon Skeet - <sk***@pobox.com>
- Michael Starberg
Sep 26 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.