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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:44:17+00:00 2026-06-16T03:44:17+00:00

Resharper recommends that these vars: List<string> senderDeviceIDList; string senderDeviceID; . . . foreach (var

  • 0

Resharper recommends that these vars:

List<string> senderDeviceIDList;
string senderDeviceID;
. . .
            foreach (var item in PlatypiIds)
            {
                senderDeviceIDList = await GetSenderDeviceIDForSenderID(item);
                senderDeviceID = senderDeviceIDList[0];

…can be declared in inner scope, like so:

    foreach (var item in PlatypiIds)
    {
        List<string> senderDeviceIDList = await GetSenderDeviceIDForSenderID(item);
        string senderDeviceID = senderDeviceIDList[0];

…but is that really “more better”? Doesn’t that cause the vars to be declared N times (once for each foreach loop)?

  • 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-16T03:44:19+00:00Added an answer on June 16, 2026 at 3:44 am

    There is no any benefit in terms of performance or memory allocation here, as variables inside or oustside of the if scope are declared in the IL, by the way.

    The only benefit is localization of the variable scope. Move it to the scope where it’s used, which brings goodness like:

    • easy refactoring (may be the most important)

    • readability. If you see variable inside the scope, you know that its used only inside that scope and if you see some variable that apparently is not inside, you know that changing it can affect other parts of the code. So changing it introduce some potential danger.

    In short, it’s about readability and usability of the code you’re writing and does not introduce any performance or memory consumption benefits.

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

Sidebar

Related Questions

ReSharper has proposed me to make the following changes: From: foreach (var item in
Resharper wanted me to change this code: foreach (var item in cmbxColor1.Items) { cmbxColor2.Items.Add(item);
I've upgraded Resharper from 5 version to 6 version. After that when I type
ReSharper 4.5's test runner will run MSTest tests out of the box, and that's
Resharper 5 can convert my foreach loops to Linq queries. Which I like. But
In Resharper I edited the inspection severity of the 'use var keyword when possible'
ReSharper sometimes hints that I can make some of my random utility methods in
I was working with a DataTable and noticed that Resharper recommended that I can
ReSharper suggested to enumerate an IEnumerable<T> to a list or array since I had
Resharper tells me that MemberInfo.DeclaringType can never be null: However when that code is

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.