由成员交叉的两个列表(Intersection of two lists by a member)
我有一个像这样的对象:
public class myObject { public string Name {get; set;} public string ID {get; set;} }
我有两个这样的列表
List<myObject> list1 = new List<myObject>(); list1.Add(new myObject(){Name = Jason, ID = 1}); list1.Add(new myObject(){Name = Jonathan, ID = 2}); list1.Add(new myObject(){Name = Kevin, ID = 3}); List<myObject> list2 = new List<myObject>(); list2.Add(new myObject(){Name = Jennifer, ID = 5}); list2.Add(new myObject(){Name = Samantha, ID = 2}); list2.Add(new myObject(){Name = Lucy, ID = 9});
我希望通过
ID
来交叉这两个列表。 我的意思是我想把Jonathan和Samantha的对象放在另一个列表中。 我怎样才能做到这一点? 谢谢。I have an object like this :
public class myObject { public string Name {get; set;} public string ID {get; set;} }
I have two lists like this
List<myObject> list1 = new List<myObject>(); list1.Add(new myObject(){Name = Jason, ID = 1}); list1.Add(new myObject(){Name = Jonathan, ID = 2}); list1.Add(new myObject(){Name = Kevin, ID = 3}); List<myObject> list2 = new List<myObject>(); list2.Add(new myObject(){Name = Jennifer, ID = 5}); list2.Add(new myObject(){Name = Samantha, ID = 2}); list2.Add(new myObject(){Name = Lucy, ID = 9});
I want to intersect these two lists by their
ID
s. I mean I want to get Jonathan's and Samantha's objects in another list. How can I do that? Thanks.
原文:https://stackoverflow.com/questions/44022114
更新时间:2024-03-29 15:03
最满意答案
我认为这样的事情应该有效:
branch :: Tree a b -> [[b]] branch (Leaf _) = [[]] branch (Branch (a, right) (b, left)) = map (a :) (branch right) ++ map (b :) (branch left)
I think something like this should work:
branch :: Tree a b -> [[b]] branch (Leaf _) = [[]] branch (Branch (a, right) (b, left)) = map (a :) (branch right) ++ map (b :) (branch left)
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
分支列表排序(list of branches sorting)[2023-12-10]
这是一个单行解决方案,虽然不太高效: parents = [ 2, 3, 1, 5, 4, 7, 8, 9, 6, 10 ] children = [ [4,5], [0,11], [6,10], [1,7], [8,9], [12,13], [14,15], [16,17], [18,19], [20,21] ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我认为这样的事情应该有效: branch :: Tree a b -> [[b]] branch (Leaf _) = [[]] branch (Branch (a, right) (b, left)) = map (a :) (branch right) ++ map (b :) (branch left) I think something like this should work: branch :: Tree a b -> ...
-
您可以使用递归函数从顶部解析treeview ,因此treeview每个根音都是一个SQL语句: 例如: 功能码: string getHead(TreeViewItem t) { string s = ""; if (t.Items.Count == 0) //get the condition { return s=t.Header.ToStri ...
-
经过长时间的搜索和尝试错误的方法,我已经设法找到一个关闭自定义级别的孩子的解决方案 这是lvl 3孩子的解决方案 $('.tree li>ul>li>ul').hide(); $('.tree li:first').show(); After a long search and try-error methods , i've manage to find a solution for closing at a custom level of children here is the solution f ...
-
列表中的树路径(Tree path in a List of Lists)[2023-09-12]
这是非常不寻常的(例如,问一个树与其所有节点的平面列表之间的关系更为常见,DCG很适合),可能是这样的: tree_list(nil, []). tree_list(tree(Node,Left,Right), [Lefts,Node,Rights]) :- tree_list(Left, Lefts), tree_list(Right, Rights). 例: ?- tree_list(tree(a,tree(b,nil,tree(d,nil,nil)),tree(c,n ... -
很酷的问题,工作很有趣。 我试图彻底,结果变得很长,我希望它仍然可读。 码: ########################## #Input data cleaned a bit# ########################## lines = ["Fred,Karl,Technician,2010", "Karl,Cathy,VP,2009", "Cathy,NULL,CEO,2007", "Vince,Cathy,Technician,20 ...
-
如何CI在VSTS中构建分支(How to CI build branches in VSTS)[2022-05-18]
您可以在构建定义的末尾添加powershell脚本任务以通过Rest API触发发布,我创建了一个简单的代码示例供您参考: if ($env:BUILD_SOURCEBRANCHNAME -eq "master") { $collectionuri = $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI $buildid = $env:BUILD_BUILDID $project = $env:SYSTEM_TEAMPROJECT $token = $env:SYSTEM_ACC ... -
映射在树中的列表(Mapping Over List In A Tree)[2022-06-10]
1) 首先,我注意到你正在做map fa尽管a是单个值,而不是列表¹。 所以你应该做的不是map fa 。 现在问你实际问到的问题: 你是对的,它不起作用,因为c是一个树列表, mapmtree只需要一棵树。 所以你会怎么做? 您将mapmtree应用于树列表中的每个树,然后使用生成树的列表作为新Branch的树列表。 你是怎样做的? 使用列表中的map : mapmtree f (Branch a c) = Branch (f a) (map (mapmtree f) c) 2) 和1)一样,你使用ma ...