Jump to content
  • Advertisement
Sign in to follow this  
Forward

Convert Object to List<Type>

This topic is 2352 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
Sounds like you want to use generics, although I'm honestly a little fuzzy on what exactly you're asking :-)

Share this post


Link to post
Share on other sites
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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!