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

  • SEARCH
  • Home
  • 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 8717379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:17:33+00:00 2026-06-13T06:17:33+00:00

In the following code, is the Select() method smart enough to keep the size

  • 0

In the following code, is the Select() method smart enough to keep the size of the list somewhere internally for the ToArray() method to be cheap?

List<Thing> bigList = someBigList;
var bigArray = bigList.Select(t => t.SomeField).ToArray();
  • 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-13T06:17:34+00:00Added an answer on June 13, 2026 at 6:17 am

    That’s easy to check, without looking at the implementation. Just create a class that implements IList<T>, and put a trace in the Count property:

        class MyList<T> : IList<T>
        {
            private readonly IList<T> _list = new List<T>();
            public IEnumerator<T> GetEnumerator()
            {
                return _list.GetEnumerator();
            }
    
            public void Add(T item)
            {
                _list.Add(item);
            }
    
            public void Clear()
            {
                _list.Clear();
            }
    
            public bool Contains(T item)
            {
                return _list.Contains(item);
            }
    
            public void CopyTo(T[] array, int arrayIndex)
            {
                _list.CopyTo(array, arrayIndex);
            }
    
            public bool Remove(T item)
            {
                return _list.Remove(item);
            }
    
            public int Count
            {
                get
                {
                    Console.WriteLine ("Count accessed");
                    return _list.Count;
                }
            }
    
            public bool IsReadOnly
            {
                get { return _list.IsReadOnly; }
            }
    
            public int IndexOf(T item)
            {
                return _list.IndexOf(item);
            }
    
            public void Insert(int index, T item)
            {
                _list.Insert(index, item);
            }
    
            public void RemoveAt(int index)
            {
                _list.RemoveAt(index);
            }
    
            public T this[int index]
            {
                get { return _list[index]; }
                set { _list[index] = value; }
            }
    
            #region Implementation of IEnumerable
    
            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
    
            #endregion
        }
    

    If the Count property is accessed, this code should print “Count accessed”:

    var list = new MyList<int> { 1, 2, 3 };
    var array = list.Select(x => x).ToArray();
    

    But it doesn’t print anything, so no, it doesn’t keep track of the count. Of course there could be an optimization specific to List<T>, but it seems unlikely…

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

Sidebar

Related Questions

The following code: select( select m.Code + ' ' + cast(m.Completed as varchar(max)) +
I have the following code CSS select.select { color:#FFFFFF; height: 15px; width: 105px; background:#996633
I wrote the following code to select text from database,but when i echo the
I have the following mySQL code: SELECT c.categoryId, c.categoryName, c.categoryParent, c.categoryDescription, COUNT(p.productid) as totalProdsInCategory
The following code shows a button that allows you to select a file (should
The following code should pop up an alert box whenever I select a file
I have following code return (EseshEntities.Current.Users.Select(u => new { Comunity = u.Apartment.Building.District.City })).ToList(); if
I have the following code: function isValidAuthor($authorID){ $query = SELECT * FROM jos_users WHERE
In the following code I set up a change handler on a select box
Given the following code: public interface Selectable { public void select(); } public class

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.