private delegate float CalculateDelegate(float x, float y); private CalculateDelegate CalculateFunct; private CalculateDelegate CalculateAdd = delegate(float x, float y) { return x + y; }; private CalculateDelegate CalculateMult = delegate(float x, float y) { return x * y; }; // Called by CheckChanged of "Add" RadioButton private void SetAddMode(object sender, EventArgs e) { if (sender is RadioButton && ((RadioButton)sender).Checked) CalculateFunct = CalculateAdd; } // Called by CheckChanged of "Add" RadioButton private void SetMultMode(object sender, EventArgs e) { if (sender is RadioButton && ((RadioButton)sender).Checked) CalculateFunct = CalculateMult; } private void Calculate(object sender, EventArgs e) { float a,b; if (!TryParseFloatInTextBox(aTextBox, out a)) return; if (!TryParseFloatInTextBox(bTextBox, out b)) return; resultsLabel.Text = CalculateFunct(a, b).ToString(); } private bool TryParseFloatInTextBox(TextBox textBox, out float f) { if (!float.TryParse(aTextBox.Text, out f)) { Console.Beep(); aTextBox.Focus(); return false; } return true; }