Add a static value in list when using Except

我是研究僧i 提交于 2019-12-12 04:53:52

问题


I am using two lists

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

and using Except to compare and filter them.

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

this returns values as

1
2

I need to return a bool value along with that ie. the return values should be as

1 true
2 true

the return type is a List<modelClass> that has int id, bool isTrue properties

Can you help me in doing this ?


回答1:


Can't you just do this:

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


来源:https://stackoverflow.com/questions/26250875/add-a-static-value-in-list-when-using-except

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!