gpt4 book ai didi

c# - 使用 LINQ 列出

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:52 24 4
gpt4 key购买 nike

我有一个返回 Guid 列表的方法。我想要以下 linq 查询:

var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select t.Profile).ToList();

为什么会出现以下错误:

Error   4   Cannot implicitly convert type 'System.Collections.Generic.List<System.Guid?>' to 'System.Collections.Generic.List<System.Guid>'    

最佳答案

您正在检查 t.Profile 是否为 null,并且只返回有效的 Guid,因此显式转换应该有效:

var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select (Guid)t.Profile).ToList();

关于c# - 使用 LINQ 列出 <Guid>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com