使用LINQ根据单独的给定扩展数组过滤SFTPFILE

发布于 2025-01-27 20:04:41 字数 577 浏览 2 评论 0原文

我正在研究.NET Core 6解决方案。我有sftpfile ssh.net的列表以及每个扩展名和另一个扩展名列表,即.csv。我想基于列表2的linq从列表1过滤文件。 。我确实实现了解决方案,但是它正在使用循环。 sftpfile对象具有实际文件名称,因此同情心将在

我只使用以下代码中获得文件名,但我需要lt; sftpfile>

var exceptRejectedFileNames2 =  sftpFiles.Select(x => x.Name).Except(RejectedFileName.GetNames()).ToList();

filter方法如下;

public static class RejectedFileName
{
    private static readonly string[] FileNames = {".", ".."};

    public static string[] GetNames()
    {
        return FileNames;
    }
}

I am working on .NET CORE 6 solution. I have list of sftpFile SSH.NET along with each extension and another list of extensions i.e. .csv. I want to LINQ to filter files from list 1 based on list 2. i.e. if list 2 have .csv & .txt then LINQ should filter out only .csv and .txt files. I did implement solution but it is using loop. sftpFile object has property name which is actual file name so the compassion will be on that

I get the fileName only with the following code but I need list<sftpFile>

var exceptRejectedFileNames2 =  sftpFiles.Select(x => x.Name).Except(RejectedFileName.GetNames()).ToList();

filter method as below;

public static class RejectedFileName
{
    private static readonly string[] FileNames = {".", ".."};

    public static string[] GetNames()
    {
        return FileNames;
    }
}

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

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

发布评论

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

评论(1

雪花飘飘的天空 2025-02-03 20:04:41
public static class RejectedFileName
{
    private static readonly HashSet<string> FileNames = new HashSet<string>() { ".", ".." };

    public static HashSet<string> GetNames()
    {
        return FileNames;
    }
}

然后在服务课上

var files = sftpFiles.Where(x => !RejectedFileName.GetNames().Contains(x.Name)).ToList();
                            
public static class RejectedFileName
{
    private static readonly HashSet<string> FileNames = new HashSet<string>() { ".", ".." };

    public static HashSet<string> GetNames()
    {
        return FileNames;
    }
}

then in service class

var files = sftpFiles.Where(x => !RejectedFileName.GetNames().Contains(x.Name)).ToList();
                            
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文