我是初學C#的學習者。如果我有2個文本框,我可以驗證1個if
語句中的2個文本框嗎?多文本框驗證
例如:
{
string emptytextbox
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.text == "")
{
//if textbox2 is empty, then messagebox will show
emptytextbox = textBox2.text;
mbox(emptytextbox + " must be filled");
//messagebox will show "textBox2 must be filled"
//but if textbox1&2 has ben filled, but textbox3 empty,then messagebox will show "textbox3 must be filled"
}
}
我能做到這一點?
做到這要看你的需求。如果你想在兩個文本框都爲空時執行一些動作,那麼你可以有一個if語句,否則你需要多個嵌套或單獨的if條件。 – Hassan
有更好的方法來實現這個功能。你在使用Windows窗體應用程序嗎? – Hassan