pass-by-reference

C# reference collection for storing reference types

為{幸葍}努か 提交于 2019-12-24 07:09:52
问题 I like to implement a collection (something like List<T> ) which would hold all my objects that I have created in the entire life span of my application as if its an array of pointers in C++. The idea is that when my process starts I can use a central factory to create all objects and then periodically validate/invalidate their state. Basically I want to make sure that my process only deals with valid instances and I don't re-fetch information I already fetched from the database. So all my

How to modify an object property given its location within the object

孤者浪人 提交于 2019-12-24 07:04:40
问题 Given an object obj , I can modify its properties by using something like obj.a.b.c = "new value" . However, I want to be able to do this programmatically, with the property's location in the form of an array. How can I make a function that looks like this: modifyProperty(obj, ["a", "b", "c"], "new value"); and is equivalent to obj.a.b.c = "new value"; ? 回答1: You could use Array#reduce for it, with a default object if no object is available. function modifyProperty(object, path, value) { var

Toggling between filtered and non-filtered list

别来无恙 提交于 2019-12-24 06:36:09
问题 I am trying to filter out records that don't have investment amount. If you see the JSON structure , I am trying to filter the FundClassDetailsViewModel object. I am sending this data to the child component. I need to provide a toggling feature such that clicking the checkbox would show filtered list and unchecking the checkbox would contain non-filtered list. I have created an object called OriginalList which is initialized at the time of retrieving the data. I am storing the filtered list

Merge Javascript Objects and All References Pointing at Them

坚强是说给别人听的谎言 提交于 2019-12-24 04:15:06
问题 In javascript, variables referring to objects are passed a "copy of the reference". I am struggling with this concept as it relates to merging two objects, and the effect on the references to those objects. Attempting to use underscore's extend, take the following (coffeescript) code: a = { id: 1 type: "cat" name: "Angry" } b = { id: 1 type: "dog" owner: "Bill" } c = a d = c e = b _.extend(a, b) b = a d.home = "Nashville" console.log(a) //Object {id: 1, type: "dog", name: "Angry", owner:

Java changes reference but not the object itself?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 03:18:47
问题 Please see the following code: public static void main(String[] args) { Test t1 = new Test(); t1.i = 1; Test t0 = t1; Test t2 = new Test(); t2.i = 2; t0 = t2; System.out.println(t1.i); //prints 1, I thought it would print 2 } Is there any way to change t1 object after I got it from somewhere else by simple assignment without accessing t1 directly? (i.e. t1 = t0) 回答1: Here is an illustration of your program and what it does. Each state of the system is shown separated by a dashed line. Note

How to pass address of objects created in a C# List to C++ dll?

怎甘沉沦 提交于 2019-12-23 18:38:13
问题 I have been looking all over google to find some answers to my questions but do not quite understand what I have found. I have some objects which are created and stored in C# List after using System.IO to read some text files. After that, I want to send references (using const pointers) to each of these objects to the internal classes in C++ dll so that it can use them for computation of some algorithms. Here are some simple example (not actual code) of what I am doing: The C# class:

Does OCaml have the ability to pass by reference?

喜欢而已 提交于 2019-12-23 13:53:23
问题 In C++ a program can pass a reference, not value to a function. void incrementInt(int &x) { ++x; } Does OCaml offer this same functionality? 回答1: No, there is no strict equivalent. There are ref s, which are like pointers to new-allocated memory, and there are records, arrays, objects and values of other compound data types, that are passed "by object reference", which again means they act like pointer to new-allocated memory. However there's no equivalent to a pointer to a variable or a C++

Passing Values from modal form to parent form vb.net

喜你入骨 提交于 2019-12-23 12:53:44
问题 I am trying to pass information to parent form from modal form in vb.net winforms application. 1.) I created a copy of a form and displayed it using following code. dim f=new frmParent() f.show() 2.) Depending on conditions a button on frmParent opens a modal child form and asks for some informations. I used following code for that: dim f = new ChildForm() f.showDialog() Both code works fine. When user press saves in child form i need to close childForm and use the user types values in parent

Adding a clone of an object to a list in c# (prevent modification from outside)

∥☆過路亽.° 提交于 2019-12-23 11:53:41
问题 I have an object like 'obj1' which I want to add to a list. I can add it by just list1.add(obj1) .Now once I update obj1 , the object in my list is also updating! (I understand that I am dealing with references here) My requirement demands modifying the obj1 and add it to the list again! Instead of having two different objects, I have only one, because for both of them, the reference is the same - obj1 . Is there any way I can modify this obj1 and add it to the list and still not lose the old

Changing copies of lists in LISP

心已入冬 提交于 2019-12-23 11:53:25
问题 In LISP, I have a function that is passed a list. I would like to change an element of this list without changing the original list. Normally, I would use copy-list to create the local copy of the list which I will change, but this doesn't seem to be working: CL-USER> (defun test (item) (let ((copy (copy-list item))) (setf (nth 0 (nth 0 (nth 0 copy))) t) (print item) (print copy))) CL-USER> (defparameter item `(((NIL NIL) (NIL NIL) (NIL NIL)) ((NIL NIL NIL) (NIL NIL NIL)) ((3 3) (NIL NIL))))