Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys


I want to convert
List <SP_SearchHotelResult >lstHotel = HotelMaster.SearchHotel("d");
lstHotel to Lisr<hotel>. How i can do

I tried this

List<Hotel> ll = lstHotel.Cast< Hotel >().ToList();

but giving error Unable to cast object of type 'SP_SearchHotelResult' to type 'Hotel'.


Any Idea

Regards
CHinnu
Posted
Comments
Zoltán Zörgő 11-Oct-12 7:39am    
And SP_SearchHotelResult is a what? Supposing it is a list of something, how is that something related to the Hotel class?
ZurdoDev 11-Oct-12 7:51am    
These are custom classes so I am not sure how we can tell you to make them compatible.

1 solution

sp_SearchHotelResult and Hotel are two different classes. Some of the properties can be present in Hotel but not in other.
So the best way to do is
C#
List <sp_searchhotelresult>lstHotel = HotelMaster.SearchHotel("d");
List<hotel> ll = new List<hotel>();
foreach(SP_SearchHotelResult  obj in lstHostel)
{
Hotel h=new Hotel();
Hotel.ID=obj.Id;
//set values for Hotel obj here
ll.Add(h);
}</hotel></hotel></sp_searchhotelresult>
 
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