• Advertisement
Sign in to follow this  

Convert Object to List<Type>

This topic is 2256 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this code and i want to convert the object to List<Riders>
How can i do that instead of creating a new class with every items?


List<Riders> list_team_riders = new List<Riders>();


object obj = (from rider in frm.list_riders
join rcont in frm.list_ridercontract on rider.PlayerID equals rcont.riderID
where rcont.TeamID == tm.TeamID
select new { rider }).ToList();

Share this post


Link to post
Share on other sites
Advertisement
change:

select new { rider } // this syntax makes an "anonymous type", which I don't see any reason for.

to:

select rider



and change:

object obj

to:

var obj // this syntax infers the correct type from the query expression and should be List<Riders> once you change the select clause.



After you've done that, assuming your old code copies the result into list_team_riders, you can just say:

var list_team_riders = (that big query expression);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement