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

The Archive Base Latest Questions

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

I have a list that gets filled in with some data from an operation

  • 0

I have a list that gets filled in with some data from an operation and I am storing it in the memory cache. Now I want another list which contains some sub data from the list based on some condition.

As can be seen in the below code I am doing some operation on the target list. The problem is that whatever changes I am doing to the target list is also being done to the mainList. I think its because of the reference is same or something.

All I need is that operation on the target list not affect data inside the main list.

List<Item> target = mainList;
SomeOperationFunction(target);

 void List<Item> SomeOperationFunction(List<Item> target)
{
  target.removeat(3);
  return target;
}
  • 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-16T05:16:45+00:00Added an answer on June 16, 2026 at 5:16 am

    You need to clone your list in your method, because List<T> is a class, so it’s reference-type and is passed by reference.

    For example:

    List<Item> SomeOperationFunction(List<Item> target)
    {
      List<Item> tmp = target.ToList();
      tmp.RemoveAt(3);
      return tmp;
    }
    

    Or

    List<Item> SomeOperationFunction(List<Item> target)
    {
      List<Item> tmp = new List<Item>(target);
      tmp.RemoveAt(3);
      return tmp;
    }
    

    or

    List<Item> SomeOperationFunction(List<Item> target)
    {
      List<Item> tmp = new List<Item>();
      tmp.AddRange(target);
      tmp.RemoveAt(3);
      return tmp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drop down list that gets its data from a php web
I have a VBA Word Macro that gets words from .txt list and color
In my C# project I have a static List that gets filled immediately when
I have a drop down list that gets populated from ViewModel: public class OrgPages
I have a baseclass that handles returning data from the relevant class/table. I want
I have created a list form that gets attached to a main form in
I have a Java program that is supplied a directory name, gets a list
I have a list that I am trying to fill with numbers from a
I have a list that I want to loop through (for trimtemp in trim)
I have one list that I want to take a slice of, reverse that

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.