pass-by-reference

Trouble understanding pass by reference

六眼飞鱼酱① 提交于 2019-12-23 10:19:07
问题 I find it really confusing to understand pass by reference in c#. In my code I have function which takes two parameters private bool SerialUnEscape(byte serialData, ref byte serialResult) { if (((SerialProcessValue)serialData == SerialProcessValue.SERIAL_PACKET_START) || ((SerialProcessValue)serialData == SerialProcessValue.SERIAL_PACKET_END)) { serialEscaped = false; serialResult = 0; return (true); } } else if (serialEscaped) { if ((SerialProcessValue)serialData == SerialProcessValue.SERIAL

How do I pass lots of variables to and from a function in Python?

拥有回忆 提交于 2019-12-23 10:14:39
问题 I do scientific programming, and often want to show users prompts and variable pairs, let them edit the variables, and then do the calulations with the new variables. I do this so often, that I wrote a wxPython class to move this code out of the main program. You set up a list for each variable with the type of the variable (string, float, int), the prompt, and the variable's current value. You then place all of these lists in one big list, and my utility creates a neatly formated wxPython

ByRef not working in VBA with value type from a class

▼魔方 西西 提交于 2019-12-23 09:25:57
问题 I always used ByRef successfully, until now. I need a function to modify a Double from a class-object. To illustrate, consider the following program. Class1.cls: Public d As Double Sub Test() Dim c As Class1, d As Double Set c = New Class1 c.d = 5 d = 5 ChangeVar c.d ChangeVar d Debug.Print c.d Debug.Print d End Sub Sub ChangeVar(ByRef d As Double) d = 10 End Sub For my surprise, the above example will output 5 10 Anybody? 回答1: Under the hood aClassInstance.publicVariable is encapsulated as a

Pass by Value in Java

大憨熊 提交于 2019-12-23 05:46:15
问题 import java.util.Arrays; public class Test { public static void main(String... args) { String[] strings = new String[] { "foo", "bar" }; changeReference(strings); System.out.println(Arrays.toString(strings)); // still [foo, bar] changeValue(strings); System.out.println(Arrays.toString(strings)); // [foo, foo] } public static void changeReference(String[] strings) { strings = new String[] { "foo", "foo" }; } public static void changeValue(String[] strings) { strings[1] = "foo"; } } Can anyone

Pass by Reference v. Pass by Pointer — Merits? [duplicate]

心不动则不痛 提交于 2019-12-23 04:36:19
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: When pass-by-pointer is preferred to pass-by-reference in C++? Are there benefits of passing by pointer over passing by reference in C++? How to pass objects to functions in C++? Hi all, I'm working to develop a large object oriented c++ application framework as part of my chemical engineering graduate research. I find that many of my functions take pointers to custom objects or STL objects. I find that in

Modify const char * in C

有些话、适合烂在心里 提交于 2019-12-23 04:29:16
问题 I am practicing for interviews. The problem Im currently stuck on is reversing a constant string in C. I know that since str2 is const, I can modify the location str2 points to, but not its value. I have a function below called reverse_const. It will reverse the const char *str_const in place and print it. However, when I try to print st2 after reversal from the main method, the string isn't reversed anymore. Its like reverse_const() is temporarily changing the memory location of str2. What

C# object modification

故事扮演 提交于 2019-12-23 03:08:44
问题 I think this is really a very lame question, but I guess on SO I will receive the answer faster than by googling it myself :) Let's say I have some class with a constructor: public class TestClass { private readonly IRepository repository; public TestClass(IRepository repository) { this.repository = repository; // Here is the non-obvious line - it invokes some // method, which changes the internal contents of // the repository object. repository.AddSomething(...); } } And now: IRepository

Object Parameters in a Constructor

自作多情 提交于 2019-12-23 02:58:15
问题 first of all I apologize if my question is difficult to understand. I'm having a hard time trying to explain exactly what I need help with. I am new to Java and the concept of passing by reference etc. Basically, I need to know why the below code is incorrect. How do I tell Java to use a method for an object passed in as a parameter of the constructor? Apologies again, and thanks for reading! public ClassOne(ClassTwo twoObject){ } public boolean OneMethod(){ twoObject.MethodName(); //

why java RMI can't get return value by reference

拟墨画扇 提交于 2019-12-23 02:07:09
问题 In RMI, I can only get return value by InetSocketAddress address = new InetSocketAddress(hostname, port); Server server = Stub.create(Server.class, address); int return = server.getValue(); But, I can't get it by public class Return { int value; } InetSocketAddress address = new InetSocketAddress(hostname, port); Server server = Stub.create(Server.class, address); Return return = new Return(); server.getValue(return); I know arguments will be serialized and deserialized, but that's not my

Passing object in reference / one place to style objects

时光毁灭记忆、已成空白 提交于 2019-12-22 18:33:01
问题 I got quite a large application which is currently being styled up. To save me changing all the buttons in the IDE/Object Inspector I am planning on just doing a few functions for the main objects like procedure StyleButton(AButton : TButton) begin AButton.Color := clGreen; AButton.Font.Style = [fsBold]; end; etc etc and then add that to the forms onCreates as needed StyleButton(Button1); whatever etc There is no issue passing objects in params like this. It does just reference the first