Click here to Skip to main content
15,917,875 members
Home / Discussions / C#
   

C#

 
AnswerRe: declaring user defined class arrays Pin
DaveyM6919-Oct-07 1:37
professionalDaveyM6919-Oct-07 1:37 
QuestionThis is my first post Pin
Challavijju19-Oct-07 0:26
Challavijju19-Oct-07 0:26 
AnswerRe: This is my first post Pin
Abhijit Jana19-Oct-07 1:35
professionalAbhijit Jana19-Oct-07 1:35 
QuestionProblem accessing Exchange server from windows vista [modified] Pin
Suj_7819-Oct-07 0:21
Suj_7819-Oct-07 0:21 
QuestionDelegates Pin
kabutar19-Oct-07 0:04
kabutar19-Oct-07 0:04 
AnswerRe: Delegates Pin
leppie19-Oct-07 4:55
leppie19-Oct-07 4:55 
QuestionShould we use 'ref' keyword while passing objects also... Pin
Spunky Coder19-Oct-07 0:04
Spunky Coder19-Oct-07 0:04 
AnswerRe: Should we use 'ref' keyword while passing objects also... Pin
DavidNohejl19-Oct-07 0:33
DavidNohejl19-Oct-07 0:33 
Spunky Coder wrote:
public static void changevalue(Manager man)
{

Manager emp2 = new Manager();
emp2.name = "TopLevelEmployee";

man = emp2;


}


This is correct. Objects are passed as reference, but that means that instead of copying whole object, reference to object is copied.
changevalue(Manager man) <- copy of "pointer" to instance Manager
{

Manager emp2 = new Manager(); <- local variable
emp2.name = "TopLevelEmployee"; <- you do changes to local variable

man = emp2; <- you assign the copy of pointer to instance to local instance


} <- all is forgotten when method returns</code>


Why is that called passing by reference? If it was passed by value, following code:
changevalue(Manager man) <- copy of instance of Manager
{

man.name = "TopLevelEmployee"; <- you do changes to copy

}

would NOT change name of man outside the method. As you can try, it indeed does change the name, because objects are passed by reference.

If you really want to change the reference to man, use keyword ref. (think about pointer to pointer)



[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

GeneralRe: Should we use 'ref' keyword while passing objects also... Pin
Spunky Coder19-Oct-07 0:46
Spunky Coder19-Oct-07 0:46 
GeneralRe: Should we use 'ref' keyword while passing objects also... Pin
DavidNohejl19-Oct-07 1:00
DavidNohejl19-Oct-07 1:00 
GeneralRe: Should we use 'ref' keyword while passing objects also... Pin
Spunky Coder19-Oct-07 1:04
Spunky Coder19-Oct-07 1:04 
GeneralRe: Should we use 'ref' keyword while passing objects also... Pin
DavidNohejl19-Oct-07 1:32
DavidNohejl19-Oct-07 1:32 
AnswerRe: Should we use 'ref' keyword while passing objects also... Pin
Stefan Troschuetz19-Oct-07 0:38
Stefan Troschuetz19-Oct-07 0:38 
AnswerRe: Should we use 'ref' keyword while passing objects also... Pin
laserbaronen19-Oct-07 0:41
laserbaronen19-Oct-07 0:41 
AnswerRe: Should we use 'ref' keyword while passing objects also... Pin
Spunky Coder19-Oct-07 1:01
Spunky Coder19-Oct-07 1:01 
Questionset CurrentRow in a DataGridView Pin
jmaalouly18-Oct-07 23:29
jmaalouly18-Oct-07 23:29 
AnswerRe: set CurrentRow in a DataGridView Pin
leppie19-Oct-07 5:05
leppie19-Oct-07 5:05 
QuestionToolStripMenuItems from SQL Pin
hobbsieoz18-Oct-07 23:18
hobbsieoz18-Oct-07 23:18 
AnswerRe: ToolStripMenuItems from SQL Pin
Jacky Yiu19-Oct-07 0:00
Jacky Yiu19-Oct-07 0:00 
GeneralRe: ToolStripMenuItems from SQL Pin
hobbsieoz19-Oct-07 0:02
hobbsieoz19-Oct-07 0:02 
AnswerRe: ToolStripMenuItems from SQL Pin
Jacky Yiu23-Oct-07 16:34
Jacky Yiu23-Oct-07 16:34 
QuestionC# 64-bit DLL? Pin
George_George18-Oct-07 23:15
George_George18-Oct-07 23:15 
AnswerRe: C# 64-bit DLL? Pin
martin_hughes19-Oct-07 0:14
martin_hughes19-Oct-07 0:14 
Questionnextline Pin
zeeShan anSari18-Oct-07 23:00
zeeShan anSari18-Oct-07 23:00 
AnswerRe: nextline Pin
Eduard Keilholz18-Oct-07 23:05
Eduard Keilholz18-Oct-07 23:05 

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.