Jump to content
  • Advertisement
Sign in to follow this  
Forward

Convert Object to List<Type>

This topic is 2493 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!