【问题标题】:Add a static value in list when using Except使用除外时在列表中添加静态值
【发布时间】:2014-10-08 06:58:55
【问题描述】:

我正在使用两个列表

List<int> a = {1,2,3};
List<int> b = {3};

并使用 except 来比较和过滤它们。

var diff = a.Except(b).ToList();

这会返回值

1
2

我需要同时返回一个布尔值,即。返回值应为

1 true
2 true

返回类型是具有int id, bool isTrue 属性的List&lt;modelClass&gt;

你能帮我做这件事吗?

【问题讨论】:

标签: c# linq except


【解决方案1】:

你不能这样做吗:

var diff = a.Except(b)
            .Select(s=>new modelClass(){id = s, isTrue = true})
            .ToList();

【讨论】:

    猜你喜欢
    • 2019-01-18
    • 2014-03-09
    • 2021-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多