c# - Conver radiobutton to a char -


i have 3 radio buttons. please see image.

radio buttons

i define variable

char temp; 

what want

if "male" selected

temp = "m"; 

if "female" selected then

temp = "f"; 

if "both" selected then

temp = "b". 

my unfinished code:

temp = convert.tochar(this.controls.oftype<radiobutton>().firstordefault(r => r.checked)); 

thanks advice.

edit: controls in groupbox. in debug mode. got error.

?groupbox4.controls.oftype() {system.linq.enumerable.oftypeiterator} source: null , ?groupbox4.controls.oftype().firstordefault(r=>r.checked).text expression cannot contain lambda expressions

edit 2: see image. run code exception. error

if understood correctly, based on (not-so-recommended) assumption each radiobutton's name starts different letter.

temp = convert.tochar(this.controls.oftype<radiobutton>().firstordefault(r => r.checked).name.substring(0, 1)); 

edit: same assumption based on text property instead of name property

    temp = convert.tochar(this.controls.oftype<radiobutton>().firstordefault(r => r.checked).text.substring(0, 1)); 

edit2: (based on ops edit - checking checked radiobutton exists):

radiobutton rb = this.controls.oftype<radiobutton>().firstordefault(r => r.checked);  if (rb != null) {     temp= rb.text[0]; } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -