Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Copy or reference? Pin
Daniel Strigl5-Jul-02 2:21
Daniel Strigl5-Jul-02 2:21 
GeneralRe: Copy or reference? Pin
Bo Norgaard5-Jul-02 2:32
Bo Norgaard5-Jul-02 2:32 
AnswerRe: Copy or reference? Pin
Rüpel5-Jul-02 2:21
Rüpel5-Jul-02 2:21 
GeneralRe: Copy or reference? Pin
Nick Parker5-Jul-02 18:54
protectorNick Parker5-Jul-02 18:54 
AnswerRe: Copy or reference? Pin
leppie5-Jul-02 4:35
leppie5-Jul-02 4:35 
GeneralRe: Copy or reference? Pin
SimonS5-Jul-02 10:00
SimonS5-Jul-02 10:00 
GeneralRe: Copy or reference? Pin
James T. Johnson5-Jul-02 16:18
James T. Johnson5-Jul-02 16:18 
AnswerRe: Copy or reference? Pin
James T. Johnson5-Jul-02 16:35
James T. Johnson5-Jul-02 16:35 
To clear it all up since there have been either incorrect or misleading statements mentioned.

o is a reference to a copy of i; a is a reference to whatever o is referencing.

Here is a small program which illustrates that

using System;
 
namespace test
{
    public class Test
    {
        public static void Main(string [] args)
        {
            int a = 1;
            object o = a;
            object o2 = o;
 
            Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
 
            // Change the value of 'a'
            a = 2;
 
	    Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
 
            // Change what 'o' references
            o = 3;
 
            Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
        }
    }
}
The output should be
a = 1, o = 1, o2 = 1<br />
a = 2, o = 1, o2 = 1<br />
a = 2, o = 3, o2 = 1


HTH,

James
"Java is free - and worth every penny." - Christian Graus
GeneralRe: Copy or reference? Pin
Daniel Strigl7-Jul-02 20:46
Daniel Strigl7-Jul-02 20:46 
GeneralRe: Copy or reference? Pin
James T. Johnson7-Jul-02 22:18
James T. Johnson7-Jul-02 22:18 
GeneralRe: Copy or reference? Pin
Daniel Strigl7-Jul-02 22:26
Daniel Strigl7-Jul-02 22:26 
AnswerRe: Copy or reference? Pin
7-Jul-02 16:01
suss7-Jul-02 16:01 
Generalenabling pictures during processing Pin
Rüpel5-Jul-02 1:02
Rüpel5-Jul-02 1:02 
GeneralRe: enabling pictures during processing Pin
Rüpel5-Jul-02 2:06
Rüpel5-Jul-02 2:06 
GeneralRe: enabling pictures during processing Pin
leppie5-Jul-02 2:08
leppie5-Jul-02 2:08 
GeneralRe: enabling pictures during processing Pin
Rüpel5-Jul-02 2:28
Rüpel5-Jul-02 2:28 
GeneralEXCEL Access Pin
Özgür5-Jul-02 0:22
Özgür5-Jul-02 0:22 
GeneralRe: EXCEL Access Pin
7-Jul-02 16:16
suss7-Jul-02 16:16 
GeneralRemove focus from Form Pin
Bo Norgaard4-Jul-02 20:47
Bo Norgaard4-Jul-02 20:47 
GeneralRe: Remove focus from Form Pin
Bo Norgaard4-Jul-02 23:21
Bo Norgaard4-Jul-02 23:21 
GeneralWrite User in the Event Log Pin
Vanclei4-Jul-02 4:50
Vanclei4-Jul-02 4:50 
Generalunsafe code Pin
Member 169774-Jul-02 2:23
Member 169774-Jul-02 2:23 
GeneralRe: unsafe code Pin
James T. Johnson4-Jul-02 7:07
James T. Johnson4-Jul-02 7:07 
GeneralRe: unsafe code Pin
Nish Nishant4-Jul-02 15:24
sitebuilderNish Nishant4-Jul-02 15:24 
GeneralOk You C# People Pin
Swinefeaster4-Jul-02 1:11
Swinefeaster4-Jul-02 1:11 

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.