C#判断页面中的多个文本框输入值是否有重复的实现方法

论坛 期权论坛 脚本     
niminba   2021-5-23 02:31   363   0

本文实例讲述了C#判断页面中的多个文本框输入值是否有重复的实现方法,分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
List<string> list = new List<string>();//首先定义一个泛型数组

//这里假如说有四个文本框

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#程序设计有所帮助。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP