简体   繁体   中英

array convert error in Option Strict mode in vb.net

I'm trying to run this code in Option Strict mode off and every things is okay:

Public Function ReadALine(ByVal File_Path As String, ByVal TotalLine As Integer, ByVal Line2Read As Integer) As String
    try

        Dim Buffer  as Array 
        Dim Line As String 
        If TotalLine <= Line2Read Then
            Return "No Such Line"
        End If
        Buffer =  File.ReadAllLines(File_Path)
     Line =  Buffer(Line2Read)
        Return Line

    Catch ex As Exception

    End Try
End Function

But when I turned it on, then vb.net say this error to me :

Option Strict On disallows late binding.

In this line and under buffer value I see the red line for error:

Line = Buffer(Line2Read)

I tried to convert with ctype, to string, or integer, but the problem is not solved yet!

My friend helped to me to fix that issue. Try:

            Dim readAllLines = File.ReadAllLines(filePath)
            Dim Buffer(readAllLines.Length) As String
            Dim Line As String
            If TotalLine <= Line2Read Then
                Return "No Such Line"
            End If
            Buffer = readAllLines
            Line = Buffer(Line2Read)
            Return Line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM