【发布时间】:2015-10-25 16:34:28
【问题描述】:
我有两个这样定义的类:
class Foo
{
public string name {get; set;}
public long number {get; set;}
}
class Bar
{
//some properties
public string otherName {get; set;}
public long otherNumber {get; set;}
}
如何将这两种类型的两个IEnumerable 序列组合成一个新的匿名类型,该类型由两个类的属性组合而成。
例子:
Foo:
name1 - number1
name2 - number2
name3 - number3
Bar:
otherName1 - otherNumber1
OtherName2 - otherNumber2
Desired Result:
name1 - number1
name2 - number2
name3 - number3
otherName1 - otherNumber1
OtherName2 - otherNumber2
我在 linq 中尝试了Zipfunction,但没有成功。
【问题讨论】:
-
匿名类型包括“name”、“number”、“othername”和“othernumber”吧?
-
使用
Concat。先有共同的基类或接口,然后将两个列表连接起来。 -
@KundanSinghChouhan 实际上我想将这两个属性合二为一。看看我的例子。
-
@nawfal 我知道
Concat是如何工作的,但问题是关于两个不同的类。
标签: c# linq collections