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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:53:46+00:00 2026-05-11T12:53:46+00:00

Consider this: Requisite: //The alphabet from a-z List<char> letterRange = Enumerable.Range(‘a’, ‘z’ – ‘a’

  • 0

Consider this:

Requisite:

//The alphabet from a-z List<char> letterRange = Enumerable.Range('a', 'z' - 'a' + 1) .Select(i => (Char)i).ToList(); //97 - 122 + 1 = 26 letters/iterations 

Standard foreach:

foreach (var range in letterRange) {     Console.Write(range + ','); } Console.Write('\n'); 

Inbuilt foreach:

letterRange.ForEach(range => Console.Write(range + ',')); //delegate(char range) works as well Console.Write('\n'); 

I have tried timing them against each other and the inbuilt foreach is up to 2 times faster, which seems like a lot.

I have googled around, but I can not seem to find any answers.

Also, regarding: In .NET, which loop runs faster, 'for' or 'foreach'?

for (int i = 0; i < letterRange.Count; i++) {     Console.Write(letterRange[i] + ','); } Console.Write('\n'); 

Doesn’t act execute faster than standard foreach as far as I can tell.

  • 1 1 Answer
  • 3 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. 2026-05-11T12:53:47+00:00Added an answer on May 11, 2026 at 12:53 pm

    I think your benchmark is flawed. Console.Write is an I/O bound task and it’s the most time consuming part of your benchmark. This is a micro-benchmark and should be done very carefully for accurate results.

    Here is a benchmark: http://diditwith.net/PermaLink,guid,506c0888-8c5f-40e5-9d39-a09e2ebf3a55.aspx (It looks good but I haven’t validated it myself). The link appears to be broken as of 8/14/2015

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

Sidebar

Related Questions

Consider this: string test = ""; somestring.ToList().Take(50).Select( delegate(char x) { test += x; return
Consider this query: SELECT table1.id, table1.review, table1.time, table2.author, table2.title FROM table1, table2 WHERE table1.id
Consider this simple MySQL query: SELECT CHAR(224 USING UTF8) This isn't returning anything for
Consider this code: enum { ERR_START, ERR_CANNOTOPENFILE, ERR_CANNOTCONNECT, ERR_CANNOTCONNECTWITH, ERR_CANNOTGETHOSTNAME, ERR_CANNOTSEND, }; char* ERR_MESSAGE[]
consider this simple function def foo(l=[]): if not l: print List is empty else
Consider this layout (pulled from here ): I'd like to understand the principles behind
Consider this #define : #define msd_buffer ((volatile char *) MSD_BUFFER_ADDRESS) and this variable definition:
Consider this generic class: class TList<T> : System.Collections.Generic.List<T> { } I have another generic
Consider this list of POSIXct dates: times <- list(as.POSIXct(c(2012-07-26 00:30, 2012-07-26 6:20, 2012-07-26 10:40,
Consider this case: dll = LoadDLL() dll->do() ... void do() { char *a =

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.