Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从多维列表中选择数据_C# - Fatal编程技术网

C# 从多维列表中选择数据

C# 从多维列表中选择数据,c#,C#,有人能帮我吗?如何从List中获取List,其中剧集。Seen==false public class Show { public string Name { get; set; } public List<Episode> Episodes { get; set; } } public class Episode { public string Name { get; set; } public Nullable<bool> Seen

有人能帮我吗?如何从
List
中获取
List
,其中
剧集。Seen==false

public class Show
{
    public string Name { get; set; }
    public List<Episode> Episodes { get; set; }
}

public class Episode
{
    public string Name { get; set; }
    public Nullable<bool> Seen { get; set; }
}
公共类节目
{
公共字符串名称{get;set;}
公共列表集{get;set;}
}
公共课插曲
{
公共字符串名称{get;set;}
公共可为空的Seen{get;set;}
}

非常感谢您的旅游帮助

使用简单的
Linq
station

var episodes = shows.SelectMany(s=>s.Episodes.Where(e=>e.Seen.HasValue && !e.Seen.Value));

使用简单的
Linq
station

var episodes = shows.SelectMany(s=>s.Episodes.Where(e=>e.Seen.HasValue && !e.Seen.Value));

您可以使用LINQ执行此操作,如下所示:

using System.Linq;

IEnumerable<Episode> unseenEpisodes = (from show in shows
                        from episode in show.Episodes
                        where (episode.Seen.HasValue && episode.Seen.Value == false)
                        select episode);
使用System.Linq;
IEnumerable UnseenePiNodes=(来自shows in shows
从节目中的插曲。插曲
其中(spice.Seen.HasValue&&spice.Seen.Value==false)
选择情节);

您可以使用LINQ执行此操作,如下所示:

using System.Linq;

IEnumerable<Episode> unseenEpisodes = (from show in shows
                        from episode in show.Episodes
                        where (episode.Seen.HasValue && episode.Seen.Value == false)
                        select episode);
使用System.Linq;
IEnumerable UnseenePiNodes=(来自shows in shows
从节目中的插曲。插曲
其中(spice.Seen.HasValue&&spice.Seen.Value==false)
选择情节);

Use-LINQ:Use-LINQ:可能是因为您使用了
Select
而不是
SelectMany
@QualityCatalyst,这不是一个有效的编辑,它可能是一个不错的注释。然而,这些问题暗示这是一个
列表
@DavidG它是一个快速类型,导致了一个打字错误,只有当我看到否决票时才注意到:-)[+]对于
e.Seen.HasValue
对于
Nullable
可能是因为您使用了
Select
而不是
SelectMany
@QualityCatalyst,这是一个无效的编辑,不过,这可能是一个不错的评论。然而,这些问题暗示这是一个
列表
@DavidG它是一个快速类型,导致了一个打字错误,只有当我看到否决票时才注意到:-)[+]对于
e.Seen.HasValue
对于
可为空的