返回两个linq列表 [英] to return two linq Lists
本文介绍了返回两个linq列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我再次在LINQ中遇到新问题.一些专家可以告诉我,我有一个< tblcontact>列表.和另一个列表< tbladdress>.是否可以将两者全部归还?还是解决这种情况的其他方法???
HI all,
I am again here with a new problem in LINQ.can some expert tell me that i have a list<tblcontact> and another list<tbladdress>. is it possible to return both these together? or is some other way to solve this situation???
List<ContactsInfo> lstID = new List<ContactsInfo>();
FileStream streams = new FileStream(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "ClientInfo\\" + "tblContacts.xml", FileMode.Open, FileAccess.Read);
StreamReader readers = new StreamReader(streams);
System.Xml.Serialization.XmlSerializer serialize = new System.Xml.Serialization.XmlSerializer(typeof(List<ContactsInfo>));
XmlReader xmlreaders = new XmlTextReader(streams);
lstID = (List<ContactsInfo>)serialize.Deserialize(xmlreaders);
List<AddressInfo> AddID = new List<AddressInfo>();
FileStream streamAdd = new FileStream(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "ClientInfo\\" + "tblAddress.xml", FileMode.Open, FileAccess.Read);
StreamReader readerAdd = new StreamReader(streamAdd);
System.Xml.Serialization.XmlSerializer serializeAdd = new System.Xml.Serialization.XmlSerializer(typeof(List<AddressInfo>));
XmlReader xmlreaderAdd = new XmlTextReader(streamAdd);
AddID = (List<AddressInfo>)serializeAdd.Deserialize(xmlreaderAdd);
return lstID;
我想一起返回lstID和AddID.该怎么做??
在此先感谢
i want to return lstID and AddID together. how to do that??
thanks in advance
推荐答案
您可以像这样使用Union运算符:
You can use the Union operator like this:
List<int> a = new List<int>() { 1, 2, 3 };
List<int> b = new List<int>() { 4, 5, 6 };
List<int> c = a.Union(b).ToList();
这将为您提供所有6个数字的列表.这适用于所有基本数据类型,例如字符串等.
希望这会有所帮助.
This will give you a list with all 6 numbers. This works with all basic DataTypes such as string etc.
Hope this helps.
http://msdn.microsoft.com /en-us/vbasic/bb688084.aspx [ ^ ]
-创建
的对象 列表(对象)
或
列表(<<用于ContactInfo和AddressInfo的通用类型说一个接口>)
-然后将两个对象(lstID和AddID)都添加到创建的对象中
-并返回对象.
希望这对您有帮助...
茉莉(Jasmin)
- Create an object of
List(Of Object)
or
List(Of <common type used for ContactInfo and AddressInfo say an interface>)
- then add both the objects (lstID and AddID) into the object created
- and return the object.
Hope this helps...
Jasmin
这篇关于返回两个linq列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文