本文實例講述了C#判斷頁面中的多個文本框輸入值是否有重復的實現方法,分享給大家供大家參考。具體實現方法如下:
//這里假如說有四個文本框
string mainseat = this.textBox1.Text;
string nextseat = this.textBox2.Text;
string storeseat1 = this.textBox3.Text;
string storeseat2 = this.textBox4.Text;
if (mainseat != "")
{
list.Add(mainseat);
}
if (nextseat != "")
{
list.Add(nextseat);
}
if (storeseat1 != "")
{
list.Add(storeseat1);
}
if (storeseat2 != "")
{
list.Add(storeseat2);
}
if (list.Distinct().Count<string>() != list.Count)//排查數組中是否有重復元素
{
//此時說明有重復
}
else
//說明沒有重復
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答