「VB.net」IndexOfメソッドで指定の値があるか判定のサンプル
構文
Public Shared Function IndexOf (array As Array, value As Object) As Integer
サンプルコード
Module ModuleTest
Sub Main()
Dim cft() As String = {"AA01", "BB02", "CC03", "DD04"}
Dim resA As Integer = Array.IndexOf("AB02")
Console.WriteLine(resA)
Dim resB As Integer = Array.IndexOf("DD04")
Console.WriteLine(resB)
End Sub
End Module
Module ModuleTest
Sub Main()
Dim cft() As String = {"AA01", "BB02", "CC03", "DD04"}
Dim resA As Integer = Array.IndexOf("AB02")
Console.WriteLine(resA)
Dim resB As Integer = Array.IndexOf("DD04")
Console.WriteLine(resB)
End Sub
End Module
Module ModuleTest Sub Main() Dim cft() As String = {"AA01", "BB02", "CC03", "DD04"} Dim resA As Integer = Array.IndexOf("AB02") Console.WriteLine(resA) Dim resB As Integer = Array.IndexOf("DD04") Console.WriteLine(resB) End Sub End Module
結果
-1
3