我有一个返回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();

10-07 19:17
查看更多