Passing an array of properties to a method.

C

craigkenisston

Hi,

I created an array of objects like this :

object[] Values = {myObject.myprop, otherobject.otherprop,
thirdobject.xprop};

Then I pass it to a method. and I get the values filled in that method.
I can debug the method and values are being assigned.
But when I am in the calling procedure I no longer see the values, I
mean, they don't keep in each object's property.
I tried passing the object array by "ref" and still no luck.

Please, let me know if this is possible or I am just smoking cheap <g>.
 
A

Abubakar

Hi,
can you provide the code through which you do this, to make it more clear.

Ab.
 
J

Jon Skeet [C# MVP]

I created an array of objects like this :

object[] Values = {myObject.myprop, otherobject.otherprop,
thirdobject.xprop};

Then I pass it to a method. and I get the values filled in that method.
I can debug the method and values are being assigned.
But when I am in the calling procedure I no longer see the values, I
mean, they don't keep in each object's property.

No, they wouldn't. You're not actually passing the properties - you're
passing the values of the properties.
I tried passing the object array by "ref" and still no luck.

Please, let me know if this is possible or I am just smoking cheap <g>.

You either need to pass an array of PropertyInfos (and the objects on
which to call them), or change the array in the method call and then
afterwards do something like

myObject.myprop = values[0];
otherobject.otherprop = values[1];
thirdobject.xprop = values[2];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top