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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:46:18+00:00 2026-05-13T05:46:18+00:00

I have the following click event. protected void btnUpdate_Click(object sender, EventArgs e) { foreach

  • 0

I have the following click event.

protected void btnUpdate_Click(object sender, EventArgs e) {
        foreach (GridViewRow gvr in gvEditBulletins.Rows) {
            RadEditor re = (RadEditor)gvr.FindControl("reBulletin");
            DropDownList ddl = (DropDownList)gvr.FindControl("ddlPosition");

            // Business logic
        }
    }

Do I suffer a performance hit since I’m declaring an instance of the RadEditor and DropDownList with every iteration, or is the compiler smart enough to know to reuse the instances?

  • 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-13T05:46:18+00:00Added an answer on May 13, 2026 at 5:46 am

    First, even worrying about this is a micro-optimization; you shouldn’t worry about it until you are studying the performance of your application and profiling suggests that this method and this loop are bottlenecks. Second, yes the compiler will reuse the same instance of the local variables re and ddl.

    Here’s a very simple example:

    class Program {
        static void Main(string[] args) {
            string[] strings = new [] { "hello", "world" };
            foreach (string s in strings) {
                int i = s.Length;
            }
            return;
        }
    }
    

    Here’s the IL:

    .method private hidebysig static void Main(string[] args) cil managed {
        .entrypoint
        .maxstack 3
        .locals init (
            [0] string[] strings,
            [1] string s,
    --->    [2] int32 i,
            [3] string[] CS$0$0000,
            [4] string[] CS$6$0001,
            [5] int32 CS$7$0002,
            [6] bool CS$4$0003)
        L_0000: nop 
        L_0001: ldc.i4.2 
        L_0002: newarr string
        L_0007: stloc.3 
        L_0008: ldloc.3 
        L_0009: ldc.i4.0 
        L_000a: ldstr "hello"
        L_000f: stelem.ref 
        L_0010: ldloc.3 
        L_0011: ldc.i4.1 
        L_0012: ldstr "world"
        L_0017: stelem.ref 
        L_0018: ldloc.3 
        L_0019: stloc.0 
        L_001a: nop 
        L_001b: ldloc.0 
        L_001c: stloc.s CS$6$0001
        L_001e: ldc.i4.0 
        L_001f: stloc.s CS$7$0002
        L_0021: br.s L_0038
        L_0023: ldloc.s CS$6$0001
        L_0025: ldloc.s CS$7$0002
        L_0027: ldelem.ref 
        L_0028: stloc.1 
        L_0029: nop 
        L_002a: ldloc.1 
    --->L_002b: callvirt instance int32 [mscorlib]System.String::get_Length()
    --->L_0030: stloc.2
        L_0031: nop 
        L_0032: ldloc.s CS$7$0002
        L_0034: ldc.i4.1 
        L_0035: add 
        L_0036: stloc.s CS$7$0002
        L_0038: ldloc.s CS$7$0002
        L_003a: ldloc.s CS$6$0001
        L_003c: ldlen 
        L_003d: conv.i4 
        L_003e: clt 
        L_0040: stloc.s CS$4$0003
        L_0042: ldloc.s CS$4$0003
        L_0044: brtrue.s L_0023
        L_0046: br.s L_0048
        L_0048: ret 
    

    }

    Notice that in the locals section, the variable i is declared as occupying the second location on the stack and this is where the result of get_Length is repeatedly being stored on each iteration through the loop. (I have highlighted the relevant lines with --->s in the margin.)

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

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 387k
  • 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 Yes, just do: unless name.blank? Inside the lambda. In this… May 15, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer You want to make a static resource first, then bind… May 15, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer You can do this in a very dodgy way by… May 15, 2026 at 12:14 am

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.