Getting an error of :
Error 1 'string RadioGroupTester.Form1.chkReceipt_CheckedChanged(object, System.EventArgs)' has the wrong return type
When I compile a very simple program to understand radio and check box controls.
Here’s the code for the form is as follows:
private string rdoMastercard_CheckedChanged(object sender, EventArgs e)
{
if (rdoMastercard.Checked)
return "You have selected Mastercard";
else
return "You have selected Visa";
}
private string chkReceipt_CheckedChanged(object sender, EventArgs e)
{
if (chkReceipt.Checked)
return "You will receive a receipt";
else
return "You will not receive a receipt";
}
private string chkRecurring_CheckedChanged(object sender, EventArgs e)
{
if (chkRecurring.Checked)
{
return "You will be charged monthly";
}
else
return "This is a one time payment";
}
And here’s what the form looks like:

What am I doing wrong here? I apologize, but I’m still pretty new to C# and VS 2010.
Thanks,
Ray
You can’t return things from an event handler. Do you mean to show a message box instead? Or give feedback through a label? It would be something like:
and the same for your other examples. This example uses a message box but you can set a Label’s text or whatever.
The reason? How do you expect C# to know what you want to do when you’re returning something from an event handler? An event handler handles events, nothing more.
Edit: So for what you want to do, it would be something like: