Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7832585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:17:50+00:00 2026-06-02T12:17:50+00:00

How can I intelligently create a List<int> from an IEnumerable<CustomClass> , if CustomClass has

  • 0

How can I intelligently create a List<int> from an IEnumerable<CustomClass>, if CustomClass has a property of type int, called customProperty which I wish to use to create my List<int> ?

I know I can create a List<CustomClass> by calling instance.ToList<CustomClass>();

How can I extract the property info to populate my list? What is best practice here ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:17:53+00:00Added an answer on June 2, 2026 at 12:17 pm

    Using Linq, you can project to the property and ToList() the resulting IEnumerable<int>:

    var ints = customClasses.Select(c => c.customProperty).ToList();
    

    If you have never seen Linq extension methods before, Select is a common “projection” method. It takes a lambda expression, in this case an expression taking a type CustomClass represented as c, it returns whatever you want it to, in this case an int. As Select is working on a set (enumerable of something) you actually get an IEnumerable<int> in response, it can infer the type of IEnumerable based on your Select lambda.

    If you want a delay-run IEnumerable<int>, simply drop the ToList() call.

    I never like to impart opinion on best practice, but this is a clean one-liner that clearly shows intent (assuming basic understanding of Linq) and I see it all over the place.

    Linq Resources:

    http://www.codeproject.com/Articles/84521/LINQ-for-the-Beginner

    http://www.codeproject.com/Articles/19154/Understanding-LINQ-C

    Lambda Expression Resources:

    http://msdn.microsoft.com/en-us/library/bb397687.aspx

    Alternatively, these topics are very easily searched with terms like “LINQ tutorials” or “lambda expression tutorials”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me with this scenario? *There is a button, which when tapped,
I'm writing an iOS game (Using UIView), which has a randomly generated 2D city.
Some of my requirements are these: Create a in-memory sqlite3 database. Read a list,
I am trying to create a grammar which accepts any character or number or
I have a simple web service which serves XML datasets (they can be as
I am certain this has been beaten to death, but I can't find it.
I would like to be able to intelligently decide whether a web application has
Can we change the color of the divider? Apple documentations says, that we can
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can someone tell me how does the imdb app manage to play trailers on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.