在VB.NET中,如何结合LINQ实现条件查询并使用else分支?

2026-05-06 12:251阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计253个文字,预计阅读时间需要2分钟。

在VB.NET中,如何结合LINQ实现条件查询并使用else分支?

我有代码检查特定文件,如果条件满足,则进入stats.matching...。我用它作为每个linq的遍历:For Each文件As String In From文件1In Stats.FoundFiles Let ftpFile=Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Con

我有代码检查特定文件,然后如果条件满足,它进入stats.matching ….我使用这个为每个 linq:

在VB.NET中,如何结合LINQ实现条件查询并使用else分支?

For Each file As String In From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Contains(currentReportName) Select file1 Stats.MatchingFiles.Add(file) Next

问题是如何在这里实施其他方法.

因此,您希望使用不包含该单词的文件填充另一个集合.

Dim matching = From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Contains(currentReportName) Dim mismatching = From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where Not ftpFile.Contains(currentReportName) For Each file As String In matching Stats.MatchingFiles.Add(file) Next For Each file As String In mismatching Stats.MismatchingFiles.Add(file) Next

这是一个简单的解决方案,您也可以使用更有效的Except:

Dim mismatching = Stats.FoundFiles.Except(matching)

本文共计253个文字,预计阅读时间需要2分钟。

在VB.NET中,如何结合LINQ实现条件查询并使用else分支?

我有代码检查特定文件,如果条件满足,则进入stats.matching...。我用它作为每个linq的遍历:For Each文件As String In From文件1In Stats.FoundFiles Let ftpFile=Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Con

我有代码检查特定文件,然后如果条件满足,它进入stats.matching ….我使用这个为每个 linq:

在VB.NET中,如何结合LINQ实现条件查询并使用else分支?

For Each file As String In From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Contains(currentReportName) Select file1 Stats.MatchingFiles.Add(file) Next

问题是如何在这里实施其他方法.

因此,您希望使用不包含该单词的文件填充另一个集合.

Dim matching = From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Contains(currentReportName) Dim mismatching = From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where Not ftpFile.Contains(currentReportName) For Each file As String In matching Stats.MatchingFiles.Add(file) Next For Each file As String In mismatching Stats.MismatchingFiles.Add(file) Next

这是一个简单的解决方案,您也可以使用更有效的Except:

Dim mismatching = Stats.FoundFiles.Except(matching)