Now, the way I have it set up is that you can pass a property by reference, so that the function can edit it directly, instead of use a copy, right?
It keeps giving me an error in the FormMain_Click:
"Cannot take the address of the given expression."
Please help. Also, if I was to get this working correctly, I don't know how to get the interval set correctly. It has to do with dividing the Time by the property and the value passed, but I don't know the algorithm.
Last edited by code?; August 15th, 2009 at 04:02 AM.
Generally speaking if you're using pointers and you're not interoping with native code, you're doing it wrong. Firstly, you can't take the address of a property, which is what you've done there. You also can't pass the address of it by ref, which is what you really wanted to do.
private unsafe void FormMain_Click(object sender, EventArgs e)
int width = Width;
this.Animate(ref width, width + 50);
Width = width;
public static Control(this Control C, ref int Property, int Value, float Time)
// Calculate Steps
Property += 50;
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Like Mutant said, I think that you should go off and find a good tutorial about reference v.s. value types. You do not need to do anything special to change a reference type when passing it to another method. You are passing a copy of the reference, so modifying the object it points to will work. Now, if you need to assign the reference to a new different object in memory you will need to use the 'ref' keyword in the function signature so that the original reference is passed instead of a copy.