.net – 将2个不同类型的IEnumebles与通用接口相结合

.net – 将2个不同类型的IEnumebles与通用接口相结合,第1张

概述我已创建此接口以用作其他2个集合的组合集合. 我的两个对象(ourCars和ourTrucks)都包含有关我的汽车收藏和卡车收集的信息. 但是字段不一样,我想创建一个新的集合,将两者结合起来. Private Interface carTruckCombo Property ID As String Property make As String Property m 我已创建此接口以用作其他2个集合的组合集合.

我的两个对象(ourCars和ourTrucks)都包含有关我的汽车收藏和卡车收集的信息.

但是字段不一样,我想创建一个新的集合,将两者结合起来.

Private Interface carTruckCombo    Property ID As String      Property make As String     Property model As String End InterfaceDim cars As IEnumerable(Of ourCars) = Enumerable.Empty(Of ourCars)()Dim trucks As IEnumerable(Of ourTrucks) = Enumerable.Empty(Of ourTrucks)()

现在这就是我被卡住的地方……我现在该怎么办?

Dim combinedResults As IEnumerable(Of carTruckCombo)
解决方法
var combinedResults  =     cars.Select(c=>new carTruckCombo{ID=c.ID,make=c.make,model=c.model})    .Union(tracks.Select(t=>new carTruckCombo{ID=t.ID,make=t.make,model=t.model}));
总结

以上是内存溢出为你收集整理的.net – 将2个不同类型的IEnumebles与通用接口相结合全部内容,希望文章能够帮你解决.net – 将2个不同类型的IEnumebles与通用接口相结合所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1212907.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存