Click here to Skip to main content
15,887,872 members
Home / Discussions / C#
   

C#

 
QuestionProblem in BackUp Pin
SajjadZare7-Jun-10 19:57
SajjadZare7-Jun-10 19:57 
AnswerRe: Problem in BackUp Pin
Md. Marufuzzaman7-Jun-10 21:37
professionalMd. Marufuzzaman7-Jun-10 21:37 
GeneralRe: Problem in BackUp Pin
SajjadZare7-Jun-10 22:01
SajjadZare7-Jun-10 22:01 
AnswerRe: Problem in BackUp Pin
Mycroft Holmes7-Jun-10 22:06
professionalMycroft Holmes7-Jun-10 22:06 
QuestionPass by value Pin
jon-807-Jun-10 18:58
professionaljon-807-Jun-10 18:58 
AnswerRe: Pass by value Pin
jgauffin7-Jun-10 20:08
jgauffin7-Jun-10 20:08 
GeneralRe: Pass by value Pin
jon-807-Jun-10 20:10
professionaljon-807-Jun-10 20:10 
AnswerRe: Pass by value Pin
Deepak-VS7-Jun-10 20:11
Deepak-VS7-Jun-10 20:11 
Pass by value and pass by reference:
Passing mechanisms decide how changes made to the parameter affect the caller.

Consider the following code snippet
Ex:

class MyClass {
public int value;
}

class Program {
..void funcPassbyValue(MyClass obj) {
obj.value = 10;
obj = new MyClass();
obj.value = 5;
}

..void func2PassbyRef(ref MyClass obj) {
obj.value = 10;
obj = new MyClass();
obj.value = 5;
}

.. Main() {
MyClass passedObj = new MyClass();

funcPassbyValue(passedObj );
Console.WriteLine(passedObj .value); //Outputs 10
func2PassbyRef(ref passedObj );
Console.WriteLine(passedObj .value); //Outputs 5
}
}

You can see both the methods funcPassbyValue && func2PassbyRef differ only in their signature.

Things which happen in common to both the methods: Any changes made to the argument to the method will be reflected back (condition is the changes are done while the parameter - in this case obj - is not changed to refer other object).

what does funcPassbyValue do differently: any changes made to the parameter (obj) will be local within the method and will not change (change here means to make it refer other object) the passedObj to refer other object.
Hope this clears your doublt.
what does func2PassbyRefdo differently: any changes made to the parameter (obj) will be reflected back to the caller in this case passedObj is changed to refer to the new object created inside the method.
QuestionMessage Removed Pin
7-Jun-10 18:51
SajjadZare7-Jun-10 18:51 
AnswerRe: BackUp Pin
Mycroft Holmes7-Jun-10 19:21
professionalMycroft Holmes7-Jun-10 19:21 
QuestionNew posts emailed - please be kind Pin
mprice2147-Jun-10 17:52
mprice2147-Jun-10 17:52 
AnswerRe: New posts emailed - please be kind Pin
Luc Pattyn7-Jun-10 17:59
sitebuilderLuc Pattyn7-Jun-10 17:59 
GeneralRe: New posts emailed - please be kind Pin
mprice2147-Jun-10 18:09
mprice2147-Jun-10 18:09 
GeneralRe: New posts emailed - please be kind Pin
OriginalGriff7-Jun-10 22:23
mveOriginalGriff7-Jun-10 22:23 
GeneralRe: New posts emailed - please be kind Pin
mprice2148-Jun-10 2:37
mprice2148-Jun-10 2:37 
GeneralRe: New posts emailed - please be kind Pin
Henry Minute8-Jun-10 2:42
Henry Minute8-Jun-10 2:42 
GeneralRe: New posts emailed - please be kind Pin
mprice2148-Jun-10 3:48
mprice2148-Jun-10 3:48 
GeneralRe: New posts emailed - please be kind Pin
Pete O'Hanlon8-Jun-10 4:46
mvePete O'Hanlon8-Jun-10 4:46 
GeneralRe: New posts emailed - please be kind Pin
mprice2148-Jun-10 4:58
mprice2148-Jun-10 4:58 
GeneralRe: New posts emailed - please be kind Pin
Luc Pattyn8-Jun-10 8:59
sitebuilderLuc Pattyn8-Jun-10 8:59 
GeneralRe: New posts emailed - please be kind Pin
mprice2148-Jun-10 9:35
mprice2148-Jun-10 9:35 
GeneralRe: New posts emailed - please be kind Pin
Luc Pattyn8-Jun-10 9:36
sitebuilderLuc Pattyn8-Jun-10 9:36 
QuestionUnable to Build Release Version of Program Pin
MWRivera7-Jun-10 8:54
MWRivera7-Jun-10 8:54 
QuestionRe: Unable to Build Release Version of Program Pin
MWRivera7-Jun-10 9:27
MWRivera7-Jun-10 9:27 
AnswerRe: Unable to Build Release Version of Program Pin
MWRivera7-Jun-10 9:53
MWRivera7-Jun-10 9:53 

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.