Sure you can Code: if(button1.Text == "somet text"){ // the text of the button is equal to some text }else{ // the text of the button is something else. }
I went poking around in google and found this. Hope it helps. http://blogs.msdn.com/b/csharpfaq/a...hould-i-use-and-when-should-i-use-equals.aspx
== is correct for c# and your example is also correct. You can use the text as a kind of switch. In the OnClick event Code: if(btn.Text == "Start") { btn.Text = "Stop"; timer1.Start(); } else { btn.Text = "Start"; timer1.Stop(); }
Bobsheep is right, both are correct. Nevertheless I would prefer to use Equals... because there you could also define if you want to ignore the case or not Code: if(String.Equals(btn.Text, "Start", StringComparison.OrdialIgnoreCase)) { btn.Text = "Stop"; timer1.Start(); } else [...] Well in this case, it doesn't really matter, because the text is set by you...