Array.IndexOf help

You can post your problem related to Microsoft Visual Studio Projects here. We will try our best to help you out.
Post Reply
Johnson
Posts: 18
Joined: Sat Feb 18, 2017 9:10 am

Array.IndexOf help

Post by Johnson » Tue Mar 07, 2017 9:04 am

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.

theenggprojects
Site Admin
Posts: 25
Joined: Tue Feb 07, 2017 12:51 pm

Re: Array.IndexOf help

Post by theenggprojects » Tue Mar 14, 2017 1:04 pm

Array.IndexOf gives you the index of any element present in your array. Let's write a small code here:

Code: Select all

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);
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. :)

Post Reply