Click here to Skip to main content
15,938,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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???



XML
 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;





i want to return lstID and AddID together. how to do that??

thanks in advance
Posted
Updated 23-Jun-11 23:28pm
v5

You can use the Union operator like this:

C#
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();


This will give you a list with all 6 numbers. This works with all basic DataTypes such as string etc.

Hope this helps.
 
Share this answer
 
Comments
Saumya J Pandey 24-Jun-11 3:38am    
thanks wayne , but the issue is both the list belongs to two different tables. i am reading two xmls simultaneously in two two lists both have different classes . now i want to return both the list to a diffrent uc. so that i am able to insert the fetched value to coressponding tables simultaneously. um not getting how to do that.
Wayne Gaylard 24-Jun-11 3:48am    
You will need to explain (edit your original question) exactly what classes are stored in the lists and what result you are trying extract for me to be able to help further.
Saumya J Pandey 24-Jun-11 5:08am    
ok, i do that only
Saumya J Pandey 24-Jun-11 5:08am    
thanks
 
Share this answer
 
- 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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900