C#3.5合并的两种不同类型2列出 [英] C# 3.5 Merge 2 lists of 2 different types

查看:105
本文介绍了C#3.5合并的两种不同类型2列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2泛型列表名单,其中,TYPE1> L1 名单,其中,2型> L2 在C#3.5

I have 2 generic Lists List<type1> L1 , List<type2> L2 in C# 3.5

问题: TYPE1有一个名为键1和type2的属性有一个属性叫做KEY2 如何合并的键1 =键2 L1和L2。 这两个列表都是无序,但我欢迎就如何名单根据属性进行排序的任何想法。

Problem: type1 has an attribute called "key1" and type2 has an attribute called "key2" How to merge L1 and L2 on key1 = key2. Both lists are unsorted but I'm welcome to any ideas on how to sort the lists based on the attribute.

我希望能够合并在一个关键的两个列表。我知道这不是一本字典,它会一直很好,如果它是,但有一个非常特殊的原因,他们的名单,我不会得到到,因为这是不相关的。

I'd like to be able to merge the two lists on a key. I know it's not a dictionary and it would've been nice if it was but there is a very specific reason why they are lists which I will not get in to because that is irrelevant.

推荐答案

我相信你要求的加入操作。这是简单的,但你将需要更加具体,以获得更好的答案。

I believe you're asking for the Join operation. It's straightforward, but you are going to need to be more specific to get better answers.

var joined = from item1 in L1
             join item2 in L2
             on item1.Key1 equals item2.Key2
             orderby item1.Key1
             select new 
             {
                 // your selected objects/properties here
             };

这篇关于C#3.5合并的两种不同类型2列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆