Hi, is there a way to implement the following code in c#? how? var x = 0.0; var pos = Rect(0, 0, 100, 100); function add(a, b) { x = a + b; } function multiply(a,b) { x = a * b; } function callOperation(a, b, func, buttonName) { if (GUI.Button(pos, buttonName)) { func(a,b); } } function OnGUI() { callOperation(1,2, add, "Add"); callOperation(1,2, multiply, "Multiply"); }
Yes, using delegates. Declare a delegate with a signature matching your 'operation' functions, then use that as the type for the function argument in the callOperation() function.