String to variable
I have a variable t开发者_JAVA技巧est..
String test = TextBox1.Text;
I want to know if the user enters into this variable 04151.
if (test == "04151")
{
MessageBox.Show("Yep!");
}
Edit:
if (test.Contains("04151"))
{
MessageBox.Show("Yep!");
}
if( test == "04151" )
{
//04151 was entered
}
?
If this is some type of checking a password, I would strongly urge you to do it in a safer way than checking towards a hard coded string inside your app. There are many issues with that approach. For one, you will have to recompile your program to alter your password.
You could put the other answers in the TextChanged event, to check it every time the user changes the text
public bool Matches(string test)
{
return String.Compare(test, "04151", true) == 0;
}
精彩评论