pass-by-reference

How parameter by reference/value works in C#

自古美人都是妖i 提交于 2021-01-27 13:22:19
问题 I have this sample code: public class MyClass { public int Value { get; set; } } class Program { public static void Foo(MyClass v) { v.Value = 2; v = new MyClass(); v.Value = 3; } static void Main(string[] args) { var m = new MyClass(); m.Value = 1; Foo(m); Console.Write(m.Value); Console.ReadLine(); } } I would like to understand why the output is 2 and not 3, could you please give me some clear explanation? Thanks 回答1: I will go through with you, step by step via the debugger and we will

Fortran passing parameters with brackets prevents changes

拟墨画扇 提交于 2021-01-20 05:16:22
问题 In this question I asked about a method to explicitly prevent passed arguments to change. An obvious solutions is defining copys of the arguments and operate the algorithm on those copys. However in the comment I was pointed to the fact, that I could call the function and wrapp the argument I didn't want to change in brackets. This would have the same effect as creating a copy of that passed variables so that it would not change. But I don't understand how it works and what the brackets are

Fortran passing parameters with brackets prevents changes

孤街浪徒 提交于 2021-01-20 05:13:27
问题 In this question I asked about a method to explicitly prevent passed arguments to change. An obvious solutions is defining copys of the arguments and operate the algorithm on those copys. However in the comment I was pointed to the fact, that I could call the function and wrapp the argument I didn't want to change in brackets. This would have the same effect as creating a copy of that passed variables so that it would not change. But I don't understand how it works and what the brackets are

Object Passing Reference vs Value [closed]

余生长醉 提交于 2021-01-01 17:56:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 days ago . Improve this question I have looked at all the articles I could find in this site and there is a lot of opinion that at times is confusing or at odds. This is where my research in my own application has lead me. and I will try to state it as simply as possible. My concern is not

Object Passing Reference vs Value [closed]

拟墨画扇 提交于 2021-01-01 17:55:35
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 days ago . Improve this question I have looked at all the articles I could find in this site and there is a lot of opinion that at times is confusing or at odds. This is where my research in my own application has lead me. and I will try to state it as simply as possible. My concern is not

Object Passing Reference vs Value [closed]

我的未来我决定 提交于 2021-01-01 17:52:52
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 days ago . Improve this question I have looked at all the articles I could find in this site and there is a lot of opinion that at times is confusing or at odds. This is where my research in my own application has lead me. and I will try to state it as simply as possible. My concern is not

Object Passing Reference vs Value [closed]

蹲街弑〆低调 提交于 2021-01-01 17:51:50
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 days ago . Improve this question I have looked at all the articles I could find in this site and there is a lot of opinion that at times is confusing or at odds. This is where my research in my own application has lead me. and I will try to state it as simply as possible. My concern is not

Object Passing Reference vs Value [closed]

白昼怎懂夜的黑 提交于 2021-01-01 17:48:39
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 days ago . Improve this question I have looked at all the articles I could find in this site and there is a lot of opinion that at times is confusing or at odds. This is where my research in my own application has lead me. and I will try to state it as simply as possible. My concern is not

Pass-by-reference differences in C++ vs Python

南笙酒味 提交于 2021-01-01 09:18:24
问题 I have a little bit of C++ background. I am currently learning Python and am trying to understand how the function parameters are passed. I know this question is asked numerous times up here, but since I am not a Computer Science major, a lot of discussions threads are rather esoteric to me, plus, I've not seen a lot of comparisons on this topic between different languages, so I thought I'd give a new post a try. The situation is this: My understanding is that Python only pass by reference (i

Can I change String object's value passed to my method?

丶灬走出姿态 提交于 2020-12-29 08:55:20
问题 I found the following question Is Java "pass-by-reference" or "pass-by-value"?. I read almost all of it, but could not find out yet what should I do if I want the foo(-) method, to change my String 's value ? (maybe or not reference too, it doesn't matter to me). void foo(String errorText){ errorText="bla bla"; } int main(){ String error="initial"; foo(error); System.out.println(error); } I want to see bla bla on the console. Is it possible? 回答1: You can't change the value of errorText in foo