加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net – 对于每个使用linq如何使用else

发布时间:2020-12-17 07:13:59 所属栏目:百科 来源:网络整理
导读:我有代码检查特定文件,然后如果条件满足,它进入stats.matching ….我使用这个为每个 linq: For Each file As String In From file1 In Stats.FoundFiles Let ftpFile = Utils.ToLowerWithoutSpaces(file1) Where ftpFile.Contains(currentReportName) Selec
我有代码检查特定文件,然后如果条件满足,它进入stats.matching ….我使用这个为每个 linq:

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读