Click here to Skip to main content
15,915,702 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with events Pin
Leslie Sanford24-Nov-05 6:58
Leslie Sanford24-Nov-05 6:58 
QuestionTreeView question. Pin
zaboboa24-Nov-05 4:26
zaboboa24-Nov-05 4:26 
AnswerRe: TreeView question. Pin
Robert Rohde24-Nov-05 4:39
Robert Rohde24-Nov-05 4:39 
QuestionMethod parameters Pin
1nsp1r3d24-Nov-05 3:15
1nsp1r3d24-Nov-05 3:15 
AnswerRe: Method parameters Pin
Leslie Sanford24-Nov-05 3:40
Leslie Sanford24-Nov-05 3:40 
GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:15
Colin Angus Mackay24-Nov-05 4:15 
AnswerRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:25
Colin Angus Mackay24-Nov-05 4:25 
GeneralRe: Method parameters Pin
Leslie Sanford24-Nov-05 4:46
Leslie Sanford24-Nov-05 4:46 
Colin Angus Mackay wrote:
As you can see, the object of class A is passed by reference because when its property is updated in the method, the update is reflected in the Main method after the call.


I'm sorry, but this isn't corrent. The variable mainA is passed by value to AnotherMethod. The parameterA is another variable that references the same object in memory as mainA.

Changing the property value in AnotherMethod changes the object that is being referenced by both mainA and parameterA. That is why the change is reflected outside of AnotherMethod.

Operations on parameterA itself are not reflected outside of that method:

static void AnotherMethod(A parameterA)        
{
    Console.WriteLine("In AnotherMethod");            
    Console.WriteLine(parameterA.SomeValue);            
    parameterA = new A();                    // Allocated new object.
    parameterA.SomeValue = "This value was set in AnotherMethod";               
    Console.WriteLine(parameterA.SomeValue);            
    Console.WriteLine("Exiting AnotherMethod");        
}


If you were to pass mainA by reference, changes to parameterA itself would also change mainA.

static void AnotherMethod(ref A parameterA)        
{
    Console.WriteLine("In AnotherMethod");            
    Console.WriteLine(parameterA.SomeValue);            
    parameterA = new A();                    // Allocated new object.
    parameterA.SomeValue = "This value was set in AnotherMethod";               
    Console.WriteLine(parameterA.SomeValue);            
    Console.WriteLine("Exiting AnotherMethod");        
}

GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 4:58
Colin Angus Mackay24-Nov-05 4:58 
GeneralRe: Method parameters Pin
Leslie Sanford24-Nov-05 5:34
Leslie Sanford24-Nov-05 5:34 
GeneralRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 5:44
Colin Angus Mackay24-Nov-05 5:44 
AnswerRe: Method parameters Pin
Colin Angus Mackay24-Nov-05 5:02
Colin Angus Mackay24-Nov-05 5:02 
QuestionData types in reports (rdls) Pin
doph24-Nov-05 1:50
doph24-Nov-05 1:50 
QuestionConverting decimal to String Pin
Subrahmanyam K24-Nov-05 1:37
Subrahmanyam K24-Nov-05 1:37 
AnswerRe: Converting decimal to String Pin
J4amieC24-Nov-05 2:02
J4amieC24-Nov-05 2:02 
AnswerRe: Converting decimal to String Pin
Craig G Fraser24-Nov-05 2:04
Craig G Fraser24-Nov-05 2:04 
QuestionRegarding Strong name Pin
A.Grover24-Nov-05 1:23
A.Grover24-Nov-05 1:23 
AnswerRe: Regarding Strong name Pin
S. Senthil Kumar24-Nov-05 2:19
S. Senthil Kumar24-Nov-05 2:19 
GeneralRe: Regarding Strong name Pin
A.Grover24-Nov-05 23:14
A.Grover24-Nov-05 23:14 
Questionclient/server communication Pin
batmanAgen24-Nov-05 1:08
batmanAgen24-Nov-05 1:08 
QuestionGenetating XML Pin
Gktony24-Nov-05 0:56
Gktony24-Nov-05 0:56 
AnswerRe: Genetating XML Pin
J4amieC24-Nov-05 1:33
J4amieC24-Nov-05 1:33 
GeneralRe: Genetating XML Pin
Gktony24-Nov-05 3:06
Gktony24-Nov-05 3:06 
GeneralRe: Genetating XML Pin
J4amieC24-Nov-05 4:32
J4amieC24-Nov-05 4:32 
QuestionHow to make a Line Graph Pin
Emyat24-Nov-05 0:24
Emyat24-Nov-05 0:24 

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.