473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Delegates - Value Type or Reference Type?

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
4 8108
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: NotYetaNurd | last post by:
Hi all, I read that delegates are type safe and Functional pointers are not!!... in this context what does type safety mean? can anyone of you throw some light on it regards, ...
3
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
6
by: Aryeh Holzer | last post by:
Let me start with a quote from the C# Programmers Reference (where I learned the cool word "covariance"): "When a delegate method has a return type that is more derived than the delegate...
3
by: karthick.ramachandran | last post by:
Hi, I was just reading this article http://www.netobjectives.com/resources/downloads/Best_Practices_CSharp_Delegates.pdf In which the author had mentioned <quote> Delegates would appear...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
1
by: Bruce Wood | last post by:
I'm trying to "genericize" the following class. At the moment I have derived classes for each different type of event handler / event arguments, and I wanted to have a single, generic, catch-all...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
2
by: BobLewiston | last post by:
The concept of delegates (references to methods) per se is new to me (although I used function pointers in C years ago), and although the literature acknowledges that there are significant...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.