在数组vb.net 2005上检测重复数字的最快方法 [英] Fastest way to detect duplicate numbers on array vb.net 2005
本文介绍了在数组vb.net 2005上检测重复数字的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目,允许用户输入1到50之间的5个不同数字.但是我想在保存到数据库之前验证它,我将是5个唯一数字.最好和最快的方法是什么?
I have this project that let user inputs 5 different numbers from 1 to 50. But I want to validate it before saving to DB that i will be 5 unique numbers. What's the best and fastest way to do this?
推荐答案
检查此代码
Private Function HasDuplicates(ByVal arr As Array) As Boolean
For i As Integer = 0 To arr.Length - 1
If Not arr(i) Is Nothing Then
Dim l As Integer = Array.LastIndexOf(arr, arr(i))
If l <> i Then Return True
End If
Next
Return False
End Function
这篇关于在数组vb.net 2005上检测重复数字的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文