显示“表”的所有内容在 VB.NET 中使用 LINQ 创建

发布于 2024-10-24 12:12:08 字数 1088 浏览 2 评论 0原文

从我问的上一个问题开始工作(回答得很好)..我遇到了另一个障碍...在下面的代码中

Public Sub Main()

    Dim EntireFile As String
    Dim oRead As System.IO.StreamReader
    oRead = File.OpenText("testschedule.txt")
    EntireFile = oRead.ReadToEnd

    Dim table As New List(Of List(Of String))

    ' Process the file
    For Each line As String In EntireFile.Split(Environment.NewLine)
        Dim row As New List(Of String)
        For Each value In line.Split(",")
            row.Add(value)
        Next

        table.Add(row)
    Next

    ' Display all contents of 5th column in the "table" using LINQ 

    Dim v = From c In table Where c(5) = ""


    For Each x As List(Of String) In v
        Console.WriteLine(x(0)) ' printing the 1st column only
    Next

    Console.WriteLine("Value of (2, 3): " + table(1)(2))
End Sub

`

上面写着 Dim v = From c In table where c(5) = "" 空白引号仅接受在该列中查找的特定数字。 例如:

Dim v = From c In tableWhere c(5) = "7" 只会显示该列中的任何 7。通常会有许多不同的值,我希望它打印该列中的所有内容,我只是无法弄清楚让它显示所选列中所有内容的命令

再次很多很多谢谢!

Working from a previous question I asked (which was answered very well).. Ive come across another snag... In the following code

Public Sub Main()

    Dim EntireFile As String
    Dim oRead As System.IO.StreamReader
    oRead = File.OpenText("testschedule.txt")
    EntireFile = oRead.ReadToEnd

    Dim table As New List(Of List(Of String))

    ' Process the file
    For Each line As String In EntireFile.Split(Environment.NewLine)
        Dim row As New List(Of String)
        For Each value In line.Split(",")
            row.Add(value)
        Next

        table.Add(row)
    Next

    ' Display all contents of 5th column in the "table" using LINQ 

    Dim v = From c In table Where c(5) = ""


    For Each x As List(Of String) In v
        Console.WriteLine(x(0)) ' printing the 1st column only
    Next

    Console.WriteLine("Value of (2, 3): " + table(1)(2))
End Sub

`

The area where it says Dim v = From c In table Where c(5) = "" the blank quotations will only accept a specific number that its looking for in that column.
For Example:

Dim v = From c In table Where c(5) = "7" Will only show me any 7's in that column. Normally there will be many different values and I want it to print everything in that column, I just cant figure out the command to have it display everything in the selected column

Once again Many MANY Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哑剧 2024-10-31 12:12:08

如果要显示所有行(准确地说:IEnumerable 中的项目),只需删除 Where 条件

Dim v = From c In table

即可。注意:table 是对于您的列表来说,这不是一个很好的名称,它引导我们想到 SQL。这只是 Linq2Objects,您不查询表,而是使用与 Linq2SQL 非常相似的语法查询普通对象,而 Linq2SQL 又深受 SQL 的启发。

If you want to show all rows (to be precise: items in the IEnumerable), just remove the Where condition

Dim v = From c In table

Just a note: table is not a very good name for your list, it leads the thought to SQL. This is just Linq2Objects and you don't query tables you query plain objects with a syntax very similar to Linq2SQL that in turn is heavily inspired by SQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文