我有一个返回 Guid 列表的方法。我想要以下 linq 查询:
var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select t.Profile).ToList();
Run Code Online (Sandbox Code Playgroud)
为什么会出现以下错误:
Error 4 Cannot implicitly convert type 'System.Collections.Generic.List<System.Guid?>' to 'System.Collections.Generic.List<System.Guid>'
Run Code Online (Sandbox Code Playgroud)
您正在检查是否t.Profile为空,并且只返回有效的 Guid,因此显式转换应该可以工作:
var results = (from t in CurrentDataSource.Table1
where t.Manager == userId && t.Profile != null
select (Guid)t.Profile).ToList();
Run Code Online (Sandbox Code Playgroud)