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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:02:03+00:00 2026-05-30T01:02:03+00:00

In Visual Studio Re-Sharper keeps recommending I convert a for loop to a linq

  • 0

In Visual Studio Re-Sharper keeps recommending I convert a for loop to a linq expression but what is the reason for this?

Which is faster?

Here are some example loops where resharper suggests a linq conversion:

foreach (XmlNode legendEntryNode in _legendEntryNodes)
{
    var xmlElement = legendEntryNode["FeatureType"];

    if (xmlElement == null || !xmlElement.InnerText.Equals(featuretype)) continue;

    var xmlNodeList = legendEntryNode.SelectNodes("Themes/Theme");

    if (xmlNodeList != null)

    foreach (XmlNode themeNode in xmlNodeList)
    {
        var element = themeNode["Value"];

        if (element == null || !element.InnerText.Equals(v)) continue;

        var xmlElement1 = themeNode["Icon"];

        if (xmlElement1 != null)
        {
            string iconname = "<ms:ICON>" + xmlElement1.InnerText + "</ms:ICON>";

            var element1 = themeNode["Highlight"];

            if (element1 != null)
            {
                string highlightname = "<ms:HIGHLIGHT>" + element1.InnerText + "</ms:HIGHLIGHT>";
                gml = gml.Insert(c, iconname + highlightname);

                c += (iconname.Length + highlightname.Length);
            }
        }
        break;
    }
}

And this simpler example:

for (int i = 0; i < getPointsRequest.Attribs.Length; i++)
{
    string attribName = getPointsRequest.Attribs[i].AttributeName;

    if (!String.IsNullOrEmpty(attribName))
    {
        sqlQuery += "<ms:" + attribName + ">||\"" + attribName + "\"||</ms:" + attribName + ">";
    }
}
  • 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-30T01:02:06+00:00Added an answer on May 30, 2026 at 1:02 am

    Speed is very often irrelevant in large portions of your code – you should write code the simplest way, and then measure it to make sure it’s fast enough.

    If your for loop is really just querying, then LINQ is absolutely a great way to end up with more readable code. It’s not universally applicable, but it’s something you should at least bear in mind frequently.

    Quite often a for loop can be converted into a query to be evaluated lazily, and then a foreach loop which performs some action on each value returned by the query. That can help separate the two aspects, letting you focus on one at a time when reading the code. It’s important to keep LINQ queries as queries though, rather than using side-effects within them – it’s designed to have a functional approach, which really doesn’t mix pleasantly with side-effects.

    If you have some concrete examples, we could give more opinions about which loops would make sense to convert to use LINQ, and which wouldn’t.

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

Sidebar

Related Questions

Visual studio keeps including sourceannotations.h to my C++ projects. This file seems to be
Visual studio is pretty good but doesn't create stored procedures automatically. Iron Speed designer
Visual Studio keeps trying to indent the code inside namespaces. For example: namespace Foo
Visual Studio compiles the projects into dlls as I want it to, but when
Visual Studio has thrown a useless exception which I think is caused by the
Visual Studio 2008 is great as text editor, but it lacks Python syntax highlighting,
Visual Studio 2008, C# 3.0. I have a method below which calls an event
Visual Studio Templates has folder structure like this: /ProjectTemplatesCache /CSharp /Windows /1033 /ClassLibrary.zip --
Visual Studio is x86 until at least the 2010 release comes around update: this
Visual Studio gives a warning when trying to do that, but does not prevent

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.