"没什么"数组中的项 [英] "Nothing" item in an array

查看:63
本文介绍了"没什么"数组中的项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:

我正在排序数组,列表中的第一项是空元素。我确保我的文本文件没有任何空行,但我仍然得到第一个元素是Nothing



文本文件:

C

D

E

A

A

B



我的尝试:



Hello:
I am sorting an array and the first item on the list in an empty element. I made sure my text file does not have any empty lines but still I get the first element to be "Nothing"

Text file:
C
D
E
A
A
B

What I have tried:

Dim File1Reader As New System.IO.StreamReader(TextBox1.Text)
Dim lineCount1 = File.ReadAllLines(TextBox1.Text).Length

Dim File1line As String
Dim file1items(lineCount1) As String
Do While File1Reader.Peek() <> -1
    File1line = File1Reader.ReadLine
    If File1line.Length > 0 Then
        file1items(i) = File1line
    End If

    i = i + 1
Loop
Dim filetable1 As New List(Of Data)

For x = 0 To (lineCount1 - 2)

    System.Array.Sort(Of String)(file1items)

    If file1items(x) = file1items(x + 1) Then
        c = c + 1
    Else
        c = 1
    End If

    filetable1.Add(New Data(file1items(x), c))
Next

推荐答案

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



可能的问题:如果你在最后一个有用的行之后有一个CR / LF,你就有一个空行。在运行调试器时要注意变量。否则,它是数据依赖的,我们无法为你测试。



建议:注意关于你的不良做法的评论。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Possible problem: if you have a CR/LF after the last useful line, you have an empty line. Be attentive to the variables as you run the debugger. Said otherwise, it is data dependent, we can't test it for you.

Advice: Pay attention to the comments about your bad practices.


这篇关于&QUOT;没什么&QUOT;数组中的项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆