Getting values throw dynamically created winfom

S

sobmir

A I'm new to c# and I came from c++ also.
I want to create dynamicaly winform to get some data. I create a array
of object as a description of variable which I want to get. I pass this
array to a function which build a form, show the edit fields and return
changed values. Changed values are stored in my array of objects but
these original values are not changed.

Short code snipet ( this is working)
// ---- c# ----
struct desc {
object o;
enum otype t;
}
int i;
string s;
// I want to get new values for i and s;
desc o1 = new desc( i, t_int );
desc o2 = new desc(s, t_str );

desc [] d = new desc[] { o1, o2 };

get_value( d ); // this methode create winform, with dynamic contents,
get the data, and return a values.

// and now I need to:
i = (int)o1.o; // I want to skip these two lines
s=(string)o2.o;
//--------------------------------------------
In c++ I can do this like:
struct desc {
object o;
enum otype t;
}
int i;
string s;
desc d[] = { {&i, t_int}, {&s, t_str}};
get_value( d ); // this methode create winform, with dynamic contents,
get the data, and return a values.
// and at the end the original values are changed
//-------------------------------------------------

Is this possible to simplify c# solution? I want to ommit last two
asignments.

MiSo
 
C

chanmm

In order to pass parameter as reference type you need to use ref keyword for
example:
get_value(ref d);

chanmm
 
M

MiSo

I've tried this, but it doesn't help me.
Like you can see, I want to first store set of variables in array and
then call get_value( d)
d array is a object and is referenced automaticaly.
I can't change values of int and string.

MiSo
 

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