c# - Why it doesn't store unless when I trying to set a name for a radio button during change? -


i apologize newbie question. have 3 radio buttons in windows form application user selects 1 of them. have these 3 in group box , attempted identify string , use in message box later in code.

string name; if (radiobutton1.checked == true){   name = radiobutton1.text; } else if (radiobutton2.checked == true) { name = radiobutton2.text; } 

then have button displays message:

message box.show("welcome " + name + "how you?"); 

the output of welcome how instead of welcome bob how you? unless have selected 1 radio button changed , pressed different one. can please explain happening here , why displaying name if radio button changed?

might code helps

   string value = "";    bool ischecked = radiobutton1.checked;    if(ischecked )    value=radiobutton1.text;    else    value=radiobutton2.text;     messagebox.show("welcome " + value + "how you?"); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -