c# and references

  • Thread starter Thread starter Klaus Bonadt
  • Start date Start date
K

Klaus Bonadt

Hi,

I know how to pass references to methods. This works fine.
But what about storing such a reference as a class member?
I did not find a solution for this.

Any help is highly appreciated.
Thanks.

Klaus
 
I know how to pass references to methods. This works fine.
But what about storing such a reference as a class member?
I did not find a solution for this.

If you want something like function-pointers you could use delegates.
If you want to use real pointers to members like fields you'll have no luck.
You can pass every variable per ref to a function but you can't store them
persistent. You have to keep a reference to the whole object to manipulate
its field at a later time.

void doit(ref a) { a++ } // declare the function like that

doit(ref myobject.a); // then call it like that
 
Back
Top