Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 0:11
George_George30-Sep-08 0:11 
GeneralRe: passing by reference v.s. passing by value Pin
Guffa30-Sep-08 8:18
Guffa30-Sep-08 8:18 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 22:20
George_George30-Sep-08 22:20 
GeneralRe: passing by reference v.s. passing by value Pin
Paul Conrad28-Sep-08 5:53
professionalPaul Conrad28-Sep-08 5:53 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 0:12
George_George30-Sep-08 0:12 
AnswerRe: passing by reference v.s. passing by value Pin
Guffa28-Sep-08 1:32
Guffa28-Sep-08 1:32 
GeneralRe: passing by reference v.s. passing by value Pin
George_George28-Sep-08 1:42
George_George28-Sep-08 1:42 
GeneralRe: passing by reference v.s. passing by value Pin
Guffa28-Sep-08 5:19
Guffa28-Sep-08 5:19 
George_George wrote:
Could you explicitly point out what do you think are the differences between passing by reference and passing by value of a value type please?


When a value type is passed by value, the value is simply copied to the stack when doing the call. When passed by reference (using the ref or out keywords), a pointer to the variable is put on the stack when doing the call.

One good thing to know when understanding how reference types and value types are passed, is that a reference is a value type. (pause to let it sink in Wink | ;) ) The object itself is a reference type and is stored on the heap, but the reference to the object is a value type. When you pass a reference type as argument, you are actually passing the reference, and as that is a value type it's value is simply copied. When you pass a reference type by reference, it's the reference that is sent by reference, so a pointer to the reference is put on the stack.

George_George wrote:
I think you mean only value type is eligible to the discussion of choices of passing by value or passing by reference?


No, I meant that only value types fit your description of how it's sent by reference. Both value types and reference types can be sent by value or by reference. (However, when sending a reference type by reference, you are actually sending the reference to the reference type by reference.)

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: passing by reference v.s. passing by value [modified] Pin
N a v a n e e t h28-Sep-08 7:43
N a v a n e e t h28-Sep-08 7:43 
GeneralRe: passing by reference v.s. passing by value Pin
Guffa28-Sep-08 8:25
Guffa28-Sep-08 8:25 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 0:00
George_George30-Sep-08 0:00 
GeneralRe: passing by reference v.s. passing by value Pin
Guffa30-Sep-08 8:01
Guffa30-Sep-08 8:01 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 22:19
George_George30-Sep-08 22:19 
GeneralRe: passing by reference v.s. passing by value Pin
Guffa1-Oct-08 3:41
Guffa1-Oct-08 3:41 
GeneralRe: passing by reference v.s. passing by value Pin
George_George3-Oct-08 1:18
George_George3-Oct-08 1:18 
GeneralRe: passing by reference v.s. passing by value Pin
N a v a n e e t h2-Oct-08 16:50
N a v a n e e t h2-Oct-08 16:50 
GeneralRe: passing by reference v.s. passing by value Pin
George_George3-Oct-08 1:21
George_George3-Oct-08 1:21 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 0:01
George_George30-Sep-08 0:01 
GeneralRe: passing by reference v.s. passing by value Pin
George_George30-Sep-08 0:08
George_George30-Sep-08 0:08 
QuestionWS-Addressing for routing Pin
George_George27-Sep-08 23:06
George_George27-Sep-08 23:06 
QuestionQuestion on threads Pin
Dewald27-Sep-08 22:06
Dewald27-Sep-08 22:06 
AnswerRe: Question on threads Pin
Nicholas Butler27-Sep-08 23:34
sitebuilderNicholas Butler27-Sep-08 23:34 
GeneralRe: Question on threads Pin
Dewald28-Sep-08 0:32
Dewald28-Sep-08 0:32 
GeneralRe: Question on threads Pin
Nicholas Butler28-Sep-08 1:34
sitebuilderNicholas Butler28-Sep-08 1:34 
GeneralRe: Question on threads Pin
Dewald28-Sep-08 3:57
Dewald28-Sep-08 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.