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 597285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:15:48+00:00 2026-05-13T16:15:48+00:00

From what I can see, the ForEach method is available only for the List

  • 0

From what I can see, the ForEach method is available only for the List class.

Why is that? I can see no reason for ForEach not to be available to any class implementing the IEnumerable/IEnumerator interfaces, and this is a really useful method if you need to perform a small action (1 line is more readable than 1 line + 2 boilerplate foreach syntax…).

Update: I’ll clarify my question. There are perfectly valid reasons for including ForEach in sequences. There are perfectly good reasons for not including ForEachin all sequences.

But I cannot understand why would ForEach be included in just some of the sequences.

  • 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-05-13T16:15:49+00:00Added an answer on May 13, 2026 at 4:15 pm

    See Eric Lippert’s post: “foreach” vs “ForEach”

    A number of people have asked me why
    there is no Microsoft-provided
    “ForEach” sequence operator extension
    method. The List class has such a
    method already of course, but there’s
    no reason why such a method could not
    be created as an extension method for
    all sequences.

    …

    But we can go a bit deeper here. I am
    philosophically opposed to providing
    such a method, for two reasons.

    …

    The first reason is that doing so
    violates the functional programming
    principles that all the other sequence
    operators are based upon. Clearly the
    sole purpose of a call to this method
    is to cause side effects.

    …

    The second reason is that doing so
    adds zero new representational power
    to the language.

    …

    Well, the VS Languages team does not
    have any influence on what goes into
    List. I personally find the
    “ForEach” method on List
    philosophically troubling for all the
    same reasons that I would find an
    extension method on IEnumerable
    troubling. (And the VSL team does
    control that.) The one mitigating
    factor is that List is clearly
    designed to be a mutable,
    not-side-effect-free data structure,
    so using expressions that mutate it
    seems slightly less bad. — Eric

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

Sidebar

Related Questions

How do I set environment variables from Java? I see that I can do
While HTML Scraping is pretty well-documented from what I can see, and I understand
As you can see this is a question from a non web developer. I
I can get easily see what projects and dlls a single project references from
How can I create a Popup balloon like you would see from Windows Messenger
Does any one know from where can I download source code for Cassini. I
From where can I download MAPI33.dll. I got the link http://www.mapi33.adexsolutions.com/ from a site
From what I can gather, there are three categories: Never use GET and use
From where I can download Turbo C++ setup, the one with blue srceen which
From what variable can you pick up the username from Forms Authentication in Microsoft

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.