int delegate FunkcjaInt(int a, int b);
struct Pozycja
{
private string nazwa;
public string Nazwa { get { return nazwa; } }
private FunkcjaInt funkcja;
public FunkcjaInt Funkcja { get { return funkcja; } }
public Pozycja(string nazwa, FunkcjaInt funkcja)
{
this.nazwa = nazwa;
this.funkcja = funkcja;
}
}
Pozycja[] pozycje = new Pozycja[]
{
new Pozycja("dodawanie", (a, b) => a + b),
new Pozycja("odejmowanie", (a, b) => a - b),
//...
new Pozycja("costam", CosTam)
}
int CosTam(int a, int b) { /*...*/ }
//...
combobox.DisplayMember = "Nazwa";
combobox.ValueMember = "Funkcja";
combobox.DataSource = pozycje;
//...
FunkcjaInt funkcja= combobox.SelectedValue as FunkcjaInt;
c = funkcja(a, b);