473,472 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Value Types and Reference Types

Just to fix, correct me if I am wrong...
With reference types (objects), if I assign an object to another, the
assignment will be the address of the object, and not a copy of it's
contents right?
With value types (structs), if I assign an object to another, I'll be
copying it's data to the left side of the assignment, and not it's address.

This is valid with method parameters too, like, if I pass an object as a
parameter, i'll be passing a reference to the memory point where the object
is allocated, and every change made to the object in the method, will be
reflected when the method returns, again with Value Types, if I pass a value
type as a method parameter, I'm passing only the reference, in this case I
need to specify out or ref keyword in the parameter, to indicate that I want
to pass it by reference...

Few questions...
With value types, if I pass an out parameter for example, I'm passing it's
memory address to, or it works with some kind of boxing/unboxing technique
to pass these parameters? It's was just a thought, don't know if it make
sense, because I don't think that it will need to box the value type to pass
that as a reference... anyways...

I think it's that..
Thanks guys!
Nov 15 '05 #1
1 1800
Rafael Veronezi <li******@terra.com.br> wrote:
Just to fix, correct me if I am wrong...
With reference types (objects), if I assign an object to another, the
assignment will be the address of the object, and not a copy of it's
contents right?
Yup - but to make the thinking easier, you never actually assign an
object to another. You assign the value of one variable to another
variable. The values of those variables are references to start with
though.
With value types (structs), if I assign an object to another, I'll be
copying it's data to the left side of the assignment, and not it's address.
Again, you're assigning the value of one variable to another - but in
this case, the value of the variable is the actual data.
This is valid with method parameters too, like, if I pass an object as a
parameter, i'll be passing a reference to the memory point where the object
is allocated, and every change made to the object in the method, will be
reflected when the method returns, again with Value Types, if I pass a value
type as a method parameter, I'm passing only the reference, in this case I
need to specify out or ref keyword in the parameter, to indicate that I want
to pass it by reference...

Few questions...
With value types, if I pass an out parameter for example, I'm passing it's
memory address to, or it works with some kind of boxing/unboxing technique
to pass these parameters? It's was just a thought, don't know if it make
sense, because I don't think that it will need to box the value type to pass
that as a reference... anyways...


See http://www.pobox.com/~skeet/csharp/parameters.html for a careful
and hopefully pretty thorough treatment of parameter passing.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and...
19
by: daniel | last post by:
This is a pretty basic-level question, but I'd really like to know, so thanks for any help or pointers you can provide (like what I would google for ;o) Suppose: <code> myFunc() {
24
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When...
5
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that...
4
by: Jon Slaughter | last post by:
I'm reading a book on C# and it says there are 4 ways of passing types: 1. Pass value type by value 2. Pass value type by reference 3. Pass reference by value 4. Pass reference by reference. ...
11
by: garyusenet | last post by:
I have 'cli via c# on order', and in the mean time am reading 'Pro C# 2005 and the .NET platform' (Andrew Troelson). I'm just reading about the 'five types defined in the CTS'. Specifically Struct....
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
14
by: KK | last post by:
Dear All I have a small problem with using as operator on value type array. Here is an example what I am trying to do. using System; using System.Collections.Generic; using System.Text;
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.