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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:32:05+00:00 2026-06-03T05:32:05+00:00

I learning LINQ, and i want to use pending request, but i have this

  • 0

I learning LINQ, and i want to use pending request, but i have this problem

            List<string> _strs = new List<string> { "1", "2", "1", "1", "0" };
            var selind = _strs.Select((name, ind) => new { indexname = name, index = ind }).Where(o => o.indexname == "1");
            string sind = "";
            foreach (var item in selind)
                sind += item.index.ToString() + " ";
            //i get 0 2 3 
            _strs.Add("2");
            _strs.Add("1");
            sind = "";
            foreach (var item in selind)
                sind += item.index.ToString() + " ";
            //Good, i get 0 2 3 6
            _strs = new List<string>() { "1" };
            sind = "";
            foreach (var item in selind)
                sind += item.index.ToString() + " ";
            //Why i get again 0 2 3 6

Ok i understand why, but I wolud like to know two things:

  • How should i clear memory?

    selind = null;
    Or you can tell me more nice way?

  • For work with selind after total rebuild of _strs i find two way

            _strs.Clear();
            _strs.Add();
    

or call again

selind = _strs.Select((name, ind) => new { indexname = name, index = ind }).Where(o => o.indexname == "1");

Can you advice me another way?

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-03T05:32:06+00:00Added an answer on June 3, 2026 at 5:32 am

    Your query:

    _strs.Select((name, ind) => new { indexname = name, index = ind }).Where(o => o.indexname == "1");
    

    Is tied to a particular list reference in memory (whatever _strs is at that time), not to a particular variable name. They are not the same thing. When you do this:

    _strs = new List<string>() { "1" };
    

    You’re not clearing the memory reference of where _strs originally pointed. You are instead having that variable name point to a new memory location. Whereas _strs.Clear() does clear the original list.

    The best solution for your problem is to wrap the LINQ query in a function that accepts a list, so you can call it again on new lists without typing it again. Alternatively, depending on your use case, just call .Clear() when you need to start again.

    (in case this wasn’t clear, _strs = null does nothing to the list that _strs used to point to, it just makes that particular variable name invalid)

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

Sidebar

Related Questions

I am learning LINQ and this seems like a fairly simple problem. I have
I have a new project where I want to use MVC (I will be
I'm new to the C# language, and have only started learning it for use
I am learning LINQ with F#. I want to know how to use lastOrDefault.
I am learning LINQ and was trying out this example related to select clause.
I am currently learning C# and LINQ. I have lots of questions about them.
I'm learning NHibernate to learn a more robust ORM than linq to sql, but
i have just started learning linq because i like the sound of it. and
I am learning LINQ . Several examples use ObjectDumper . What is the use
I have been learning C# for the past few days for use with ASP.NET

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.