Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Delegates - Value Type or Reference Type?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Smithers - 26 Sep 2007 17:34 GMT
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.
Ido Samuelson - 26 Sep 2007 17:37 GMT
strings are immutable also and they are not value types.
delegates are not value types. they can be null :-)

> 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.
Peter Duniho - 26 Sep 2007 18:05 GMT
> 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
Jon Skeet [C# MVP] - 26 Sep 2007 19:00 GMT
> > 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
[quoted text clipped - 7 lines]
> 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!

Signature

Jon Skeet - <skeet@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

Michael Starberg - 26 Sep 2007 20:57 GMT
>> > Are delegates value types or reference types? I was just pondering the
>> > fact
[quoted text clipped - 9 lines]
>> 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.  =)

- Michael Starberg

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.