0

How do I change the following class/method to accept global variables and also return a value?

private void radioButton_CheckedChanged(object sender, EventArgs e)

Ideally, I want it to return either a string or a text. But that doesn't happen just by changing void to int or string and using return command inside it. Making the same public also doesn't seem to work.

Any inputs or suggestions, please?

---------------------EDIT-ADDED-LATER---------------------

What I am trying to do was for this - C# - How do I separately return int values from each radio GroupBox?

Community
  • 1
  • 1
Dr.Viper
  • 411
  • 2
  • 5
  • 17
  • This is an event handler which is defined to have this exact method signature. Also, this is called only when the checked changed happens in the radio button, where is the return value going to go? If you need this method to do some processing that returns a value I would suggest creating a private method to do that. – Stephen Wilson Jul 25 '16 at 08:47
  • Have a think about where this method would be returning the value to. – Notts90 Jul 25 '16 at 08:55
  • Thanks for the input. I have found out a solution from another thread where somebody needed a different solution. Please check whether it is OK. Added as answer below. – Dr.Viper Jul 25 '16 at 09:56
  • Possible duplicate of [C# - How do I separately return int values from each radio GroupBox?](https://stackoverflow.com/questions/37832724/c-sharp-how-do-i-separately-return-int-values-from-each-radio-groupbox) – Grimthorr Nov 17 '17 at 11:01

2 Answers2

0

I am afraid, what you’re saying is not possible to be achieved. This is an event handler and the event is raised internally when the checked state of your radio button is changed. The signature and return method is decided my Microsoft obviously and you cannot change the arguments of return type of event handlers.

Also returning a data type to a radio button doesn’t sound too good, and you never need that. I think your requirement might be to change some properties or controls that is existing in the UI. That could be easily done from within the event handler and doesn’t require you to modify them.

Hence there is no need for changing their signature. If you could tell more about your requirement, we could suggest a solution based on that.

ViVi
  • 4,339
  • 8
  • 29
  • 52
  • Thanks for the input. I have found out a solution from another thread where somebody needed a different solution. Please check whether it is OK. Added as answer below – Dr.Viper Jul 25 '16 at 09:59
  • If it's working for you, then fine. I can't comment on it without knowing the requirement. The answer you posted doesn't make any sense after reading your question anyway. – ViVi Jul 25 '16 at 10:13
  • Thanks for the response. My response is not clear, hence I have edited the question to show the context. What I am trying to achieve is explained here - http://stackoverflow.com/questions/37832724/c-sharp-how-do-i-separately-return-int-values-from-each-radio-groupbox . Thanks for taking the time to respond./ – Dr.Viper Jul 25 '16 at 10:35
0

Based on another thread, where some suggestion was made, I found that I am able to get this via the following way.

int value = 0;
protected void radioButton_CheckedChanged(object sender, EventArgs e)
if (radioButton.Checked)
   {
       value = 100;
   }

Can somebody review and tell whether any mistakes are there in this? It does what I want, but at what cost?

Dr.Viper
  • 411
  • 2
  • 5
  • 17