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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:11:31+00:00 2026-05-12T09:11:31+00:00

If I have this code: foreach (Char c in myString.ToLowerInvariant()) { /* code */

  • 0

If I have this code:

foreach (Char c in myString.ToLowerInvariant())
{ /* code */ }

How many times will myString.ToLowerInvariant() get called? Once (which I assume) or multiple times?

  • 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-12T09:11:31+00:00Added an answer on May 12, 2026 at 9:11 am

    Short answer: Once

    Long answer:

    The code gets compiled into the following IL. You can try it yourself by compiling the C# file and then opening it in ILDASM (distributed with Visual Studio) or .NET Reflector (which can show the disassembled code in many languages and has tooltips for IL instructions with detailed description).

    L_0008: ldloc.0 
    L_0009: callvirt instance string [mscorlib]System.String::ToLowerInvariant()
    L_000e: stloc.2 
    L_000f: ldc.i4.0 
    L_0010: stloc.3 
    L_0011: br.s L_0021
    L_0013: ldloc.2 
    L_0014: ldloc.3 
    L_0015: callvirt instance char [mscorlib]System.String::get_Chars(int32)
    L_001a: stloc.1 
    L_001b: nop 
    L_001c: nop 
    L_001d: ldloc.3 
    L_001e: ldc.i4.1 
    L_001f: add 
    L_0020: stloc.3 
    L_0021: ldloc.3 
    L_0022: ldloc.2 
    L_0023: callvirt instance int32 [mscorlib]System.String::get_Length()
    L_0028: clt 
    L_002a: stloc.s flag
    L_002c: ldloc.s flag
    L_002e: brtrue.s L_0013
    

    The actual loop condition is checked on lines L_0021 to L_002c and then there a jump at line L_002e which is executed if not all characters are processed yet. Note that it jumps to L_0013 which is after the ToLowerInvariant call.

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

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 166k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer try: OnClientClick="jQuery('#Notice').hide();return null;" or write full function in js: function… May 12, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer i would use abcPdf component, the image would be a… May 12, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer Also take a look at the Dimecasts 'Learning the Specification… May 12, 2026 at 1:14 pm

Related Questions

I have some code that is really slow. I knew it would be and
I have two strings: the first's value is catdog and the second's is got.
HI, I am trying to convert the following vba code to c# and i
Under Linux, my C++ application is using fork() and execv() to launch multiple instances
I have developed a reverse-string program. I am wondering if there is a better

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.