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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:45:45+00:00 2026-06-11T12:45:45+00:00

I would like to know which gives us a better performs on both the

  • 0

I would like to know which gives us a better performs on both the ways as given below:

1. Way 1

for(int i = 0; i < 10; i++)
{
   // do something in loop
}

2. Way 2

for(int i = Constants.Zero; i < Constants.Ten; i++)
{
    // do something in loop
}
private const int Zero = 0; 

private const int Ten = 10;

Basically I want to know that Can we increase the application performance if we use Constants in for loop variable declaration as mentioned above?

Thanks in advance !

  • 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-11T12:45:46+00:00Added an answer on June 11, 2026 at 12:45 pm

    There is no any performance benefit here, as variable declared in that way will end up into injected constants, like in your first case. So they are become basically the same.

    //code 1
    for(int i = 0; i < 10; i++)
    {
         Console.WriteLine("Hello");
    }
    
    //IL 1
    
    IL_0001:  ldc.i4.0    
    IL_0002:  stloc.0     
    IL_0003:  br.s        IL_0016
    IL_0005:  nop         
    IL_0006:  ldstr       "Hello"
    IL_000B:  call        System.Console.WriteLine
    IL_0010:  nop         
    IL_0011:  nop         
    IL_0012:  ldloc.0     
    IL_0013:  ldc.i4.1    
    IL_0014:  add         
    IL_0015:  stloc.0     
    IL_0016:  ldloc.0     
    IL_0017:  ldc.i4.s    0A 
    IL_0019:  clt         
    IL_001B:  stloc.1     
    IL_001C:  ldloc.1     
    IL_001D:  brtrue.s    IL_0005
    
    //code 2
    for(int i = Constants.Zero; i < Constants.Ten; i++)
    {
        Console.WriteLine("Hello");
    }
    
    //IL 2
    IL_0001:  ldsfld      UserQuery+Constants.Zero
    IL_0006:  stloc.0     
    IL_0007:  br.s        IL_001A
    IL_0009:  nop         
    IL_000A:  ldstr       "Hello"
    IL_000F:  call        System.Console.WriteLine
    IL_0014:  nop         
    IL_0015:  nop         
    IL_0016:  ldloc.0     
    IL_0017:  ldc.i4.1    
    IL_0018:  add         
    IL_0019:  stloc.0     
    IL_001A:  ldloc.0     
    IL_001B:  ldsfld      UserQuery+Constants.Ten
    IL_0020:  clt         
    IL_0022:  stloc.1     
    IL_0023:  ldloc.1     
    IL_0024:  brtrue.s    IL_0009
    

    In second case I used a static class to create constants.

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

Sidebar

Related Questions

I would like to know the procedure which will give the out put about
I would like to know which WP plugin should I choose to allow every
I would like to know which ViewController is currently the active one. in other
i would like to know , how ill know which inlines forms was edited?
I have 4 files and would like to know elements which are non overlapping
I would like to know the code which can enable me to get a
I would like to know list of gems which is helpful for creating a
I would like to know if there is an existent framework which can manage
I would like to know if it exist a solution to record audio which
I am creating an iphone performance app in which I would like to know

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.