检查如果值在数组中出现两次

时间:2014-03-27 05:34:04

标签: arrays vb.net arraylist

我有和数组,我想检查我的Dim值是否包含在数组中,但我需要检查它是否出现两次。

示例:

Dim value as String = "AST"

Dim zone_check_list() As String = {"AMST","AST","AST","EET","EDT"}

'if "AST" appeared twice then i will show message box

1 个答案:

答案 0 :(得分:3)

如何使用LINQ:

Imports System.Linq

Dim value as String = "AST"
Dim zone_check_list() As String = {"AMST","AST","AST","EET","EDT"}
Dim isAppearTwice As Boolean = (zone_check_list.Count(Function(x) x = value) = 2)
Console.WriteLine(isAppearTwice)