How to declare text with a line

后端 未结 4 1766
日久生厌
日久生厌 2021-01-28 23:03

I\'m new to programming and decided to take VB.net up as my first language, I\'m quite new and I\'m currently trying to write a sorting program. I\'m trying to load in a file, s

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-28 23:09

    Using currentfilereader As StreamReader = New StreamReader("S:\class" & CName & ".rtf")
        Do
            line = currentfilereader.ReadLine
            If IsNumeric(line) AndAlso CInt(line) >= 1 AndAlso CInt(line)<= 10 Then
                list.Add(line)
                Console.WriteLine(line)
            End If
        Loop Until currentfilereader.EndOfStream
    End Using
    

    Since it seems all you are wanting is values 0 - 10, you can convert line to an integer and check if it is within that range.

    AndAlso is a short-circuited comparison, meaning that as soon as one of your values is False, it'll stop comparing and carry on.

    Also, you should make sure your readers end when they find EndOfStream, rather than when your line is Nothing.

提交回复
热议问题