Array Problem

Sockreg

Member
Joined
Aug 27, 2007
Messages
12
Programming Experience
Beginner
VB.NET:
Module Module1
    Sub Main()
        Dim myArray(6) As Integer

        myArray(0) = "2"
        myArray(1) = "12"
        myArray(2) = "2"
        myArray(3) = "2"
        myArray(4) = "2"


        Console.WriteLine(myArray.IndexOf(myArray, 12))
        Console.ReadLine()

    End Sub

End Module

If I replace myArray in the writeline command with Array.IndexOf it compiles and works fine.. If i do not, it gives me this error :

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.


But it compiles also but gives me a green line under myArray.IndexOf

Any help ?
 
That's how it is with shared members, Array.IndexOf is correct usage. As the warning message tells you it will ignore incorrect usage like calling instance.sharedmember() and call class.sharedmember() anyway because that's the only way to call a shared member.
 
yep, that will do it. And also, i have another question.. can regex be used with IndexOf.. I mean i want to search an array of integers and I used array.IndexOf(myArray, \b\d{2}-\d{3}.*\w*\b) .. the regex is fine but it returns -1 :S .. I am new to VB.Net regex .. maybe i have to use some keywords ?

PS. I imported System.Text.RegularExpressions
 
Regex only searches strings.
 
u can also match integers with regex as far as i know :S .. you mean with arrays you can use only regex for strings ? can you please explain with a very small example :)
 
Regex can search the string for digits, that is true.
 
Back
Top