Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with an If statement

Status
Not open for further replies.

Samantha22

Programmer
Aug 24, 2002
1
US
For practice, I'm trying to write an app that allows a user to enter alpha & numeric characters into textBox1. textBox2 returns those characters (from textbox1), but in ascii format.
I'm trying to use an if statement to test for a character and replace it with another, however, I'm having a problem. My code is:
private void textBox1_TextChanged(object sender, System.EventArgs e)
{

textBox2.Text = textBox1.Text;

if ( textBox1.Text = 'a' )
textBox2.Text = 'Å' ;
}
The error returned is: Cannot implicitly convert type 'string' to 'bool'

I understand the error, but I do not know how to get around this. Any help in this problem is greatly appreciated.
 
You need double equal signs to do the comparison. I moved from VB6 to C# and this bites me all the time.

Try: if ( textBox1.Text == 'a' )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top