TextFieldParser.ErrorLineNumber 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回导致最近发生的 MalformedLineException 异常的行的行号。
public:
 property long ErrorLineNumber { long get(); };
	public long ErrorLineNumber { get; }
	member this.ErrorLineNumber : int64
	Public ReadOnly Property ErrorLineNumber As Long
	属性值
导致最近发生的 MalformedLineException 异常的行的行号。
示例
此示例使用 ErrorLineNumber 属性显示导致当前 MalformedLineException 异常的行的位置。
Dim FileReader As Microsoft.VisualBasic.FileIO.TextFieldParser
FileReader = My.Computer.FileSystem.OpenTextFieldParser("C:\test.txt")
Dim currentRow As String()
While Not FileReader.EndOfData
    Try
        currentRow = FileReader.ReadFields
        For Each currentField As String In currentRow
            My.Computer.FileSystem.WriteAllText(
                "C://testfile.txt", currentField, True)
        Next
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
        MsgBox("Line " & FileReader.ErrorLineNumber & " is not valid.")
    End Try
End While
	注解
MalformedLineException如果未引发异常,则返回 -1。
属性 ErrorLine 可用于显示导致异常的行号。 确定行号时,不会忽略空行和注释。
下表列出了涉及 ErrorLineNumber 属性的任务的示例。
| 功能 | 查看 | 
|---|---|
| 从带分隔符的文件读取 | 如何:读取逗号分隔的文本文件 | 
| 从固定宽度的文件读取 | 如何:读取固定宽度的文本文件 |