简体   繁体   English

vb.net中Option Strict模式下的数组转换错误

[英]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: 我正在尝试在Option Strict模式下运行此代码,并且一切正常。

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 : 但是当我打开它时,然后vb.net对我说这个错误:

Option Strict On disallows late binding. Option Strict On不允许后期绑定。

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! 我试图用ctype转换为字符串或整数,但问题尚未解决!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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