检查Array vb.net中的重复值 [英] Check Duplicate Value in Array vb.net

查看:95
本文介绍了检查Array vb.net中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何检查数组中是否有重复值?

Hi,

how can i check if there''s a duplicate value in array?

Dim array(9) as String

array(0) = Textbox1.Text
array(1) = Textbox2.Text
array(2) = Textbox3.Text
array(3) = Textbox4.Text
array(4) = Textbox5.Text
array(5) = Textbox6.Text
array(6) = Textbox7.Text
array(7) = Textbox8.Text
array(8) = Textbox9.Text
array(9) = Textbox10.Text





如果有重复的值或文本,那么te的背景颜色xtbox变为红色。





任何帮助都将受到高度赞赏。



if there''s a duplicate value or text then the backcolor of the textbox turns to red.


any help will be highly appreciated.

推荐答案

试试这个:



C#

Try this:

C#
IEnumerable<Control> ctls = this.Controls.Cast<Control>();
var txtBoxQuery = from c in ctls
                  where c is TextBox && ctls.Count(x => x.Text == c.Text) > 1
                  select c;
foreach (Control c in txtBoxQuery)
        c.BackColor = Color.Red;







VB




VB

Dim ctls As IEnumerable(Of Control) = Me.Controls.Cast(Of Control)()
Dim txtBoxQuery = From c In ctls Where TypeOf c Is TextBox And ctls.Count(Function(x) x.Text = c.Text) > 1 Select c
For Each c As Control In txtBoxQuery
   c.BackColor = Color.Red
Next


http://lmgtfy.com/?q=vb.net+check+for+duplicate+ value + in + array [ ^ ]


一些用于检查重复值的链接..然后应用您的逻辑来更改文本框的颜色..

http://www.vbforums.com/showthread.php?157498-Removing-duplicates-来自阵列 [ ^ ]

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/0754a61c-3643-49a6- 9f72-34d5d76cedf0 [ ^ ]

http ://www.visualbasicscript.com/removing-duplicate-array-values-m27947.aspx [ ^ ]
Some links for checking duplicate values..then apply your logic to change color of textbox..
http://www.vbforums.com/showthread.php?157498-Removing-duplicates-from-an-array[^]
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/0754a61c-3643-49a6-9f72-34d5d76cedf0[^]
http://www.visualbasicscript.com/removing-duplicate-array-values-m27947.aspx[^]


这篇关于检查Array vb.net中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆