I'm using C#. I have a certain number of Newtonsoft.Json.Linq.JArray, let's say A123, A124, A125, and so on.
I need to create an array or something similar of this objects in a way that, if I do something on one element of this array, is as doing in to my original objects.
Thank you.
struct Product {
public JArray A1;
public JArray A2;
public JArray A3;
public JArray A4;
};
Product obj=new Product();
JArray[] vj=new JArray[4]{obj.A1, obj.A2, obj.A3, obj.A4};
Now, I'm doing:
obj.A1=new JArray(){1,2,3,4,5};
obj.A1.Add("testo");
for every single object.
But I'd like to replace with something like this:
vj[0]=new JArray(){1,2,3,4,5};
vj[0].Add("testo");
vj[1]=new JArray(){3,5,2,3,4};
vj[1].Add("testo");
vj[2]=new JArray(){2,3,4,5,6};
vj[2].Add("testo");
vj[3]=new JArray(){2,2,3,4,5};
vj[3].Add("testo");
but if I do this, the original object, obj.A1 obj.A2 and so on, remain null. So I'm looking for a way to have, let's say, an array of pointers to JArray
JArrayis a reference type, I don't see why that shouldn't work already. Just don't create new objects, use the existing references.vj, all the referencesobj.A1-obj.A4arenull. When you assign a new array tovj[0], how should the runtime know to also assign this toobj.A1? Instead, create the arrays first on theobj, then create your array with the proper references. Then you can modify the values of the four arrays (but not replace them / create new ones).