【问题标题】:Select nonNullable values of nullable property from collection of objects with PLINQ使用 PLINQ 从对象集合中选择可空属性的非可空值
【发布时间】:2014-04-21 17:26:53
【问题描述】:

为什么当我在查询中使用 Plinq 时,例如

var notNullParameterValues = (from operation in operations.AsParallel()
                        where operation.NullableParameter.HasValue
                        select operation.NullableParameter.Value)
                        .Distinct().ToList();

resharper 用“可能的 System.InvalidOperationException”警告我?

为简单起见,操作是IList<Operation>;

public class Operation 
{
    public int? NullableParameter {get; set;}
}

更新:谢谢大家的回答。

【问题讨论】:

标签: c# linq plinq


【解决方案1】:

也许是因为 Resharper 并不完美?

我相信它也建议检查操作是否为空。

看看JetBrains Issue Tracker

【讨论】:

    【解决方案2】:
    var notNullParameterValues = (from operation in operations.AsParallel()
                                  let nullableParameter = operation.NullableParameter
                                  where nullableParameter != null
                                  select nullableParameter.Value).Distinct().ToList();
    

    【讨论】:

    • 我目前正在使用该解决方案)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 2013-06-19
    • 2017-02-21
    • 2017-10-01
    • 1970-01-01
    相关资源
    最近更新 更多