Microsoft Visual Studio Projects DISCUSSION

Array.IndexOf help

Started by syedzainnasir Array.IndexOf help
1 replies 248 views 2 participants
Latest activity · 07 Mar 2017

Array.IndexOf help

syedzainnasir Microsoft Visual Studio Projects Forum
#1
Here is my code

Dim jb As Integer
Dim ksks() As Single = {40, 50, 50, 6, 7, 8, 50}
jb = Array.IndexOf(ksks, 6)

Debug.Print(jb)

jb returns -1 no matter what number I use that is clearly in the array.

Community replies 1

Re: Array.IndexOf help

#2
Array.IndexOf gives you the index of any element present in your array. Let's write a small code here: [code] int[] array = new int[6]; array[0] = 1; array[1] = 3; array[2] = 5; array[3] = 7; array[4] = 8; array[5] = 9; int index1 = Array.IndexOf(array, 9);[/code] Now when you run it, it will give you 5 as an answer because 5 is the index of value 9. Its giving you -1 because the value whose index you are trying to check is not present in your array. :)
TEP COMMUNITY