In Javascript or Flash, I am used to passing callbacks to my button objects like this:
MAIN CLASS
function init() {
var myButton = new Button("red", doSomething);
}
function doSomething() {
log("someone clicked our button, but who?");
}
BUTTON CLASS CONSTRUCTOR
function Button(color, callback) {
addListener(mouseClick, callback);
}
This example is greatly simplified, the point is that you can pass a function name as a parameter to the Button instance. The button will then call that function once it is clicked.
Is this possible in C# ? I've read something about delegates but couldn't figure out a simple example.